[英]Jars on the java CLASSPATH environment variable are ignored
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 /”包含以下jar:
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. 我检查了CLASSPATH变量和manuel optino -cp中的路径是否100%相同。 Also an echo $CLASSPATH returns the correct path.
同样,echo $ CLASSPATH返回正确的路径。
Why do I still get this error? 为什么仍然出现此错误?
You need to export
the new classpath variable in your bashrc
line: 您需要在
bashrc
行中export
新的classpath变量:
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
. 同样,如果要编译Java的外壳是在更改bashrc文件之前创建的,则需要使用
source ~/.bashrc
重新读取bashrc文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.