bash java CLASSPATH 环境变量上的罐子被忽略
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15906233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jars on the java CLASSPATH environment variable are ignored
提问by toom
In my ~/.bashrc I export my java CLASSPATH the following way:
在我的 ~/.bashrc 中,我通过以下方式导出我的 java CLASSPATH:
CLASSPATH=$CLASSPATH:/home/user/java/libs/apache-ant-1.9.0/lib/*:/home/user/java/MyProject/libs/*
The folder "/home/user/java/MyProject/libs/" contains the following jars:
文件夹“/home/user/java/MyProject/libs/”包含以下 jars:
colt.jar mysql-connector-java-5.1.22-bin.jar
concurrent.jar postgresql-8.4-703.jdbc4.jar
When I try to compile a class of my project that imports parts the colt.jar, I get an error message:
当我尝试编译导入 colt.jar 部分的项目类时,我收到一条错误消息:
/src$ javac visualization/VisualizeCorrelationMatrix.java
visualization/VisualizeCorrelationMatrix.java:16: cannot access cern.colt.matrix.impl.SparseDoubleMatrix2D
class file for cern.colt.matrix.impl.SparseDoubleMatrix2D not found
int N = cm.columns();
^
But when compling it the followin way it works without errors:
但是当按照以下方式编译它时,它可以正常工作:
/src$ javac -cp ".:/home/user/java/MyProject/libs/*" visualization/VisualizeCorrelationMatrix.java
I checked that the paths in the CLASSPATH variable and the manuel optino -cp are 100% identical. Also an echo $CLASSPATH returns the correct path.
我检查了 CLASSPATH 变量和 manuel optino -cp 中的路径是否 100% 相同。还有一个 echo $CLASSPATH 返回正确的路径。
Why do I still get this error?
为什么我仍然收到此错误?
回答by imp25
You need to exportthe new classpath variable in your bashrcline:
您需要export在您的bashrc行中添加新的类路径变量:
export CLASSPATH=$CLASSPATH:/home/user/java/libs/apache-ant-1.9.0/lib/*:/home/user/java/MyProject/libs/*
Also if the shell you are compiling the java in was created before you changed your bashrc file you'll want to reread the bashrc file using source ~/.bashrc.
此外,如果在更改 bashrc 文件之前创建了用于编译 java 的 shell,则需要使用 .bashrc 重新读取 bashrc 文件source ~/.bashrc。

