日期:2014-05-16  浏览次数:20653 次

Linux下多个jdk引发的问题
在linux中执行javac时报如下错误:

libgcj-javac-placeholder.sh

This script is a placeholder for the /usr/bin/javac
master link required by jpackage.org conventions.  libgcj's
rmiregistry, rmic and jar tools are now slave symlinks to these
masters, and are managed by the alternatives(8) system.

This change was necessary because the rmiregistry, rmic and jar tools
installed by previous versions of libgcj conflicted with symlinks
installed by jpackage.org JVM packages.

This script was designed to be overridden by the supported RHEL3 SDK
packages, java-1.4.2-bea-devel and java-1.4.2-ibm-devel.  It is
installed as an alternative symlink as /usr/bin/javac.  It will
override a third-party (non-RHEL3) SDK's javac command if the SDK's
bin directory is listed after /usr/bin in PATH.  In that case, it is
recommended that the third-party SDK's bin directory be listed first
in PATH instead.

/usr/bin/javac: line 22: exec: gcj: not found

经过一番搜索发现,问题是在系统中安装了多个jdk。或者是路径配置有误;主要解决方法有两种:

简单方法:修改环境变量PATH,将JAVA_HOME/bin设为第一位。

较为复杂的方法:

    $ java -version
    ... placeholder message ...
    $ su -
    # alternatives --remove java /usr/share/java/libgcj-java-placeholder.sh
    # alternatives --remove javac /usr/share/java/libgcj-java-placeholder.sh
    # alternatives --remove jar /usr/bin/fastjar
    # alternatives --remove jar.1.gz /usr/share/man/man1/fastjar.1.gz
    # cd /usr/bin
    # ln -s /usr/java/jdk/bin/java java
    ... also set the links for javac etc ...
    # exit
    $ java -version
    java version "1.5.0_04"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
    Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)


第二个方法是直接删除造成初始java环境混乱的Package:
Quote:

    libgcj-devel-3.4.2-6.fc3
    libgcj-3.4.2-6.fc3