简体   繁体   English

Eclipse没有看到CLASSPATH

[英]Eclipse doesn't see CLASSPATH

I have some JAR files on my CLASSPATH environment variable. 我的CLASSPATH环境变量上有一些JAR文件。 When I open cmd and enter echo %CLASSPATH% , the paths to those JARs are part of the output. 当我打开cmd并输入echo %CLASSPATH% ,这些JAR的路径是输出的一部分。 When I try to compile and run a java class through cmd that imports classes from these JARs, it works, and I don't have to add the JARs with -cp . 当我尝试通过从这些JAR导入类的cmd编译并运行Java类时,它可以工作,并且我不必使用-cp添加JAR。

But when I try to import these classes in Eclipse, it doesn't work. 但是,当我尝试在Eclipse中导入这些类时,它不起作用。 The import cannot be resolved. 导入无法解决。 I have to add them to the build path. 我必须将它们添加到构建路径。

This means that when I get a new version of a library, I have to add it to the build path, and remove the old version, for each project that uses the library. 这意味着,当我获得库的新版本时,必须为使用该库的每个项目将其添加到构建路径中,并删除旧版本。 I also have to recompile the projects that I have runnable JARs of, because each uses its own separate copy of the library (which, by the way, just seems wasteful and unnecessary). 我还必须重新编译具有可运行JAR的项目,因为每个项目都使用自己的单独的库副本(顺便说一句,这似乎是浪费和不必要的)。 If it worked as I intended, I'd only have to change the version number in CLASSPATH . 如果它按我的预期工作,则只需更改CLASSPATH的版本号。

Is it possible to make it work like I intended? 是否可以使其按预期工作? Or is there a better way to handle JARs and JAR updates? 还是有更好的方法来处理JAR和JAR更新?

You can define a User Library in the preferences and refer to that in your projects' Java Build Path s, changing the JAR files it contains as needed. 您可以在首选项中定义一个用户库 ,并在项目的Java Build Path中引用它,并根据需要更改其中包含的JAR文件。 For updating your runnable jars automatically, that might well be better suited to a system such as Ant or Maven. 对于自动更新可运行的jar,这可能更适合于Ant或Maven之类的系统。 As for having redundant copies in your Runnable JARs, that's just part of what makes them "runnable." 至于在Runnable JAR中具有冗余副本,那只是使它们“可运行”的一部分。

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

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