简体   繁体   English

Arch Linux上的Java类路径问题

[英]Java classpath issues on arch linux

For me to get any java program to run, I have to perform the following steps: 为了让我运行任何Java程序,我必须执行以下步骤:

javac program.java
java -cp .  program

The output of echo $CLASSPATH is =/usr/share/java/ echo $CLASSPATH的输出是=/usr/share/java/
I was wondering why I have to manually specify the classpath everytime and how I can work around this issue. 我想知道为什么每次都要手动指定类路径,以及如何解决此问题。 I am using archlinux with openjdk8. 我在openjdk8中使用archlinux。 I encountered the same issue with openjdk9 as well. 我也遇到了与openjdk9相同的问题。
Any help on the topic is appreciated. 对此主题的任何帮助将不胜感激。

You have set $CLASSPATH to /usr/share/java , so java will not look in the current directory anymore. 您已将$CLASSPATH设置$CLASSPATH /usr/share/java ,因此java将不再在当前目录中查找。 To fix this, you can run unset CLASSPATH for temporarily unsetting the environment variable. 要解决此问题,您可以运行unset CLASSPATH来临时unset CLASSPATH环境变量。

Depending on wheter or not you need $CLASSPATH pointing to /usr/share/java , you can either remove the offending line (something like export CLASSPATH=/usr/share/java ) or add the line export CLASSPATH=.:$CLASSPATH at the end of the file, wherever you set your environment variables (eg ~/.bashrc , ~/.zshenv , ...). 根据您是否需要指向/usr/share/java $CLASSPATH ,可以删除有问题的行(类似于export CLASSPATH=/usr/share/java ),也可以在以下位置添加行export CLASSPATH=.:$CLASSPATH文件的末尾,无论您在何处设置环境变量(例如~/.bashrc~/.zshenv ,...)。

Cf. cf. https://wiki.archlinux.org/index.php/environment_variables https://wiki.archlinux.org/index.php/environment_variables

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM