简体   繁体   English

Java CLASSPATH环境变量上的jar会被忽略

[英]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.

相关问题 我想在引导时为我的 java 应用程序设置一个环境变量,以便类路径中的 jars 可以读取它 - I want to set an environment variable to my java application while bootstrapping such that the jars in classpath can read it Java默认的ClassPath环境变量 - Java default ClassPath environment variable 如何在Java中使用CLASSPATH环境变量指定依赖于applet的jar - How to specify applet dependent jars using CLASSPATH environmental variable in java 外部jar的Java类路径问题 - Java classpath issue with external jars 尽管使用了 CLASSPATH 环境变量,但 java.lang.ClassNotFoundException - java.lang.ClassNotFoundException in spite of using CLASSPATH environment variable 将环境变量用于Java类路径在Shell脚本中不起作用 - Using an environment variable for java classpath not working within shell script Shell脚本中的Java类路径问题-无法检测到罐子 - Issue with the java classpath in shell script - jars not detectable 在Pl / Java中将JAR设置为类路径时出现问题 - Problems setting JARs to classpath in Pl/Java 在 Java 类路径中的目录中包含所有 jar - Including all the jars in a directory within the Java classpath 声纳集成测试Againts Java类路径jars - Sonar integration tests againts java classpath jars
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM