Ubuntu 中的 Java 类路径问题

发布于 2024-09-01 13:10:33 字数 657 浏览 6 评论 0原文

首先,我运行的是 Ubuntu 9.10,

我编辑了 /etc/environment 文件,如下所示:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.20"
CLASSPATH="/home/travis/freetts/lib/freetts.jar:/home/travis/freetts/lib/jsapi.jar:."

然后运行“source /etc/environment”以确保包含更改。 然后我尝试使用以下命令编译我的简单测试程序:

javac Test.java

它会抛出一些错误,但是当我像这样编译时:

javac -cp /home/travis/freetts/lib/freetts.jar:/home/travis/ freetts/lib/jsapi.jar:. Test.java

它工作得很好,这让我相信由于某种原因 javac 没有看到 CLASSPATH 环境变量?我可以在终端中回显它和所有内容:

echo $CLASSPATH 给出我输入的内容。

对此的任何帮助将不胜感激。

First off I'm running Ubuntu 9.10

I've edited the /etc/environment file to look like this:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.20"
CLASSPATH="/home/travis/freetts/lib/freetts.jar:/home/travis/freetts/lib/jsapi.jar:."

I then run "source /etc/environment" to make sure the changes are included.
Then I try compiling my simple test program using this:

javac Test.java

It throws out a few errors, but when I compile like this:

javac -cp /home/travis/freetts/lib/freetts.jar:/home/travis/freetts/lib/jsapi.jar:. Test.java

It works just fine, this leads me to believe that for some reason javac isn't seeing the CLASSPATH environment variable? I can echo it and everything in the terminal:

echo $CLASSPATH gives me what I put in.

Any help on this would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饮惑 2024-09-08 13:10:33

如果将 export 放入 /etc/environment 中,它可以工作吗?

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
export JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.20"
export CLASSPATH="/home/travis/freetts/lib/freetts.jar:/home/travis/freetts/lib/jsapi.jar:."

我猜测在获取脚本之前没有设置 CLASSPATH ,因此您只是设置了一个局部变量。


以下是可能发生的情况的说明:

superman@metro:~$ Z=foo        # Only sets for this shell
superman@metro:~$ echo $Z
foo
superman@metro:~$ /bin/bash
superman@metro:~$ echo $Z      # Not set in sub-processes

superman@metro:~$ exit
exit
superman@metro:~$ export Z     # When exported, is part of environment
superman@metro:~$ /bin/bash
superman@metro:~$ echo $Z      # And now visible to sub-processes
foo
superman@metro:~$ exit
exit
superman@metro:~$ help export
export: export [-nf] [name[=value] ...] or export -p
     NAMEs are marked for automatic export to the environment of
    subsequently executed commands.  If the -f option is given,
    the NAMEs refer to functions.  If no NAMEs are given, or if '-p'
    is given, a list of all names that are exported in this shell is
    printed.  An argument of '-n' says to remove the export property
    from subsequent NAMEs.  An argument of '--' disables further option
    processing.

Does it work if you put export in /etc/environment?

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
export JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.20"
export CLASSPATH="/home/travis/freetts/lib/freetts.jar:/home/travis/freetts/lib/jsapi.jar:."

I'm guessing that CLASSPATH isn't set before you source the script, and so you are only setting a local variable.


Here's an illustration of what might be happening:

superman@metro:~$ Z=foo        # Only sets for this shell
superman@metro:~$ echo $Z
foo
superman@metro:~$ /bin/bash
superman@metro:~$ echo $Z      # Not set in sub-processes

superman@metro:~$ exit
exit
superman@metro:~$ export Z     # When exported, is part of environment
superman@metro:~$ /bin/bash
superman@metro:~$ echo $Z      # And now visible to sub-processes
foo
superman@metro:~$ exit
exit
superman@metro:~$ help export
export: export [-nf] [name[=value] ...] or export -p
     NAMEs are marked for automatic export to the environment of
    subsequently executed commands.  If the -f option is given,
    the NAMEs refer to functions.  If no NAMEs are given, or if '-p'
    is given, a list of all names that are exported in this shell is
    printed.  An argument of '-n' says to remove the export property
    from subsequent NAMEs.  An argument of '--' disables further option
    processing.
送君千里 2024-09-08 13:10:33

您是否导出了配置文件中的所有环境变量?我在u指定的文件中没有看到任何导出命令......使用导出并尝试一次......

Did u export all the environment variables in profile file? i didn't see any export command in the file specified by u......use export and try once......

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文