Mac OSX Leopard 中 终端java乱码的解决方法

Mac OSX Leopard 中 终端java乱码的解决方法

在Mac OSX Leopard中如果在终端程序中输入Java可以看到如下输出:
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)

where options include:
    -d32          use a 32-bit data model if available
    -d64          use a 64-bit data model if available (implies -server, only for x86_64)
    -client      to select the "client" VM
    -server      to select the "server" VM
    -jvm      is a synonym for the "client" VM  [deprecated]
    -hotspot      is a synonym for the "client" VM  [deprecated]
                  The default VM is client.
                 
    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose[:class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument

但是javac和jar命令却无法得到正确的输出,例如javac命令得到的输出为:
?÷???javac <ѡ??> <Դ?ļ?>
???У????ܵ?ѡ???????
  -g                         ???????е?????Ϣ
  -g:none                    ???????κε?????Ϣ
  -g:{lines,vars,source}     ֻ????ijЩ??????Ϣ
  -nowarn                    ???????κξ???
  -verbose                   ????йر?????????ִ?еIJ???????Ϣ
  -deprecation               ???ʹ???ѹ?ʱ?? API ??Դλ??
  -classpath <·??>            ָ???????û????ļ???λ??
  -cp <·??>                   ָ???????û????ļ???λ??
  -sourcepath <·??>           ָ??????????Դ?ļ???λ??
  -bootclasspath <·??>        ???????????ļ???λ??
  -extdirs <Ŀ¼>              ???ǰ?װ????չĿ¼??λ??
  -endorseddirs <Ŀ¼>         ????ǩ???ı?׼·????λ??
  -d <Ŀ¼>                    ָ????????ɵ????ļ???λ??
  -encoding <????>             ָ??Դ?ļ?ʹ?õ??ַ?????
  -source <?汾>               ?ṩ??ָ???汾??Դ??????
  -target <?汾>               ?????ض? VM ?汾?????ļ?
  -version                   ?汾??Ϣ
  -help                      ?????׼ѡ?????Ҫ
  -X                         ????DZ?׼ѡ?????Ҫ
  -J<??־>                     ֱ?ӽ? <??־> ???ݸ?????ʱϵͳ

主要的原因是终端程序中使用的编码格式与javac或者jar帮助文件的编码格式不同.
但是在Mac OSX Leopard中为了照顾大多数的程序,在终端中还是将编码设置为了UTF-8,可以通过set命令查看,例如:
Apple_PubSub_Socket_Render=/tmp/launch-bVZUGq/Render
BASH=/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="2" [2]="17" [3]="1" [4]="release" [5]="i386-apple-darwin9.0")
BASH_VERSION='3.2.17(1)-release'
COLUMNS=117
COMMAND_MODE=unix2003
DIRSTACK=()
DISPLAY=/tmp/launch-IZXRkN/:0
EUID=501
GROUPS=()
HISTFILE=/Users/mazhao/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/Users/mazhao
HOSTNAME=mazhaodeimac.local
HOSTTYPE=i386
IFS=$' /t/n'
LANG=zh_CN.UTF-8
LINES=39
LOGNAME=mazhao
MACHTYPE=i386-apple-darwin9.0
MAILCHECK=60
MANPATH=/usr/share/man:/usr/local/share/man:/usr/X11/man
OPTERR=1
OPTIND=1
OSTYPE=darwin9.0
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
PIPESTATUS=([0]="2" [1]="0")
PPID=641
PS1='/h:/W /u/$ '
PS2='> '
PS4='+ '
PWD=/Users/mazhao
SECURITYSESSIONID=ab40b0
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=1
SSH_AUTH_SOCK=/tmp/launch-InisMD/Listeners
TERM=xterm-color
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=240
TMPDIR=/var/folders/uA/uA4dEjP9HBWOk+6ULKESZk+++TI/-Tmp-/
UID=501
USER=mazhao
_=
__CF_USER_TEXT_ENCODING=0x1F5:25:52

要想让javac或者jar命令的帮助输出没有乱码,必须使用GB18030的编码格式,刚才也说过为了照顾大多数程序的需求,不能修改
这里的编码格式,那么则么办呢?
我们使用一个功能更加强大的终端程序,就是iTerm.
在iTerm中在info > session > Encoding 中将编码设置为GB18030即可,截图为:

在Mac中可以使用Control + Command + 3 / 4 来截图,截得的图片放在了桌面.

你可能感兴趣的:(java,osx,search,bash,终端,deprecated)