隨筆-179  評論-666  文章-29  trackbacks-0
          最近要用jfreechart,在圖表中會用到中文,
          在windows環境下,不會發生亂碼問題.
          但是部署到linux下,就發生中文亂碼問題,中文全變成方框,摸索了一段時間才將之解決。

          為了確定你的Linux環境下程序會使用的字體文件,先跑跑這個程序:from others

          1 public   class  PrintLocale  {
          2      public   static   void  main(String[] args)  {
          3         System.out.println(System.getProperty( " user.language " ));
          4         System.out.println(System.getProperty( " user.region " ));
          5         System.out.println(System.getProperty( " file.encoding " ));
          6         System.out.println(System.getProperty( " os.version " ));
          7     }

          8 }

          9

          訪問順序可以看:
          http://www-128.ibm.com/developerworks/cn/websphere/library/techarticles/yangyaping0307/waslinux.html
           
          比如: linux as 3.0 ,linux 7.3 same
          會大概有如下的訪問順序:
           
          font.properties.zh_CN.Redhat
          font.properties.zh_CN
          font.properties.zh
          font.properties
           
           
          1 . 將此文件拷貝到%JAVA_HOME%/jre/lib下面去

          serif.0=-b&h-luxi serif-medium-r-normal--*-%d-*-*-p-*-iso8859-1
              serif.
          1=-misc-ZYSong18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
          serif.italic.
          0=-b&h-luxi serif-medium-i-normal--*-%d-*-*-p-*-iso8859-1
              serif.italic.
          1=-misc-ZYSong18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
              .
            略
            
             .appendedfontpath
          =/usr/share/fonts/zh_CN/TrueType


          請注意 字符串-misc-ZYSong18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1,除了中間什么*-%--*--c*--之外
          必須跟 /usr/share/fonts/zh_CN/TrueType/fonts.dir 中的完全一致。
          如果把 ZYSong --> zysong 也是不行的。
           
          2. 設置中文環境
             我是在程序中如下設置的:

          System.setProperty("user.language","zh");     
             System.setProperty(
          "user.region","CN");


          3. 編譯代碼文件,要用
                   javac -encoding GBK   xxxxxx.java
             如果是用ant工具,
                 <target name="compile" depends="prepare" description="complie All Java source">
                    <copy todir="${build.dir}">
                      <fileset dir="${src.dir}" includes="**/*.properties" />
                   </copy>
                   <javac srcdir="${src.dir}" destdir="${build.dir}" encoding="GBK">
                      <classpath refid="project.classpath" />
                   </javac>
                </target>
           
           
          可以訪問這里的資源: http://dev.csdn.net/article/55/55126.shtm
          posted on 2006-05-20 13:10 Alpha 閱讀(3418) 評論(1)  編輯  收藏 所屬分類: Java J2EE JSP

          評論:
          # 有些人re: linux下java中文字體問題[與JfreeChart有關] 2006-06-06 13:42 | 有些人
          主站蜘蛛池模板: 上高县| 德庆县| 阿瓦提县| 泌阳县| 永年县| 修武县| 沐川县| 阿鲁科尔沁旗| 黑山县| 道孚县| 昌平区| 大安市| 汾西县| 晋江市| 象山县| 梨树县| 冀州市| 宁城县| 太仆寺旗| 屏边| 凉城县| 南部县| 武平县| 黔南| 姚安县| 余庆县| 仁化县| 涞源县| 衡阳县| 青海省| 蒙山县| 涿鹿县| 瑞昌市| 高要市| 台东市| 武清区| 宁武县| 枣庄市| 荣昌县| 柳州市| 上林县|