随笔-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 阅读(3395) 评论(1)  编辑  收藏 所属分类: Java J2EE JSP

评论:
# 有些人re: linux下java中文字体问题[与JfreeChart有关] 2006-06-06 13:42 | 有些人

只有注册用户登录后才能发表评论。


网站导航: