简体   繁体   English

Eclipse通过系统变量导入外部JAR

[英]Eclipse import external JAR via system variable

i wish to add external JAR to my project without using Eclipse GUI. 我希望在不使用Eclipse GUI的情况下将外部JAR添加到我的项目中。 i have a system variable which hold the absolute path to the JAR file, how may i add it using java code. 我有一个系统变量,它保存JAR文件的绝对路径,我该如何使用Java代码添加它。

If you set the classpath variable then all other programs for which you dont specify a classpath while compiling or executing will assume the same classpath. 如果设置了classpath变量,则在编译或执行过程中未为其指定类路径的所有其他程序将采用相同的类路径。 This will result in an issue one way or the other. 这将导致一种或另一种方式的问题。 Like Snicolas said, its a very static way of doing things. 就像Snicolas所说的,这是一种非常静态的做事方式。

Instead what I would suggest is, if you have a variable like JAR_PATH set in your OS, then use the variable itself as below: 相反,我建议的是,如果您在OS中设置了类似JAR_PATH的变量,则使用变量本身,如下所示:

Windows:  java -classpath %JAR_PATH%;<other elements of your classpath> mainclass
Unix: java -classpath $JAR_PATH:<other elements of your classpath> mainclass

what do you mean use it for compilation, or use it at run time ? 您是什么意思将其用于编译或在运行时使用它?

If you want to do both, you can set the CLASSPATH environment variable and the jar to it. 如果您想两者都做,则可以将CLASSPATH环境变量和jar设置给它。 Otherwise you could add it to your command lines for javac or java using the -classpath command line switch. 否则,您可以使用-classpath命令行开关将其添加到javac或java的命令行中。

And if you want to deploy your app using this jar, then you must follow this guide to add the jar path to the manifest 而且,如果要使用此jar部署应用程序,则必须遵循此指南将jar路径添加到清单中

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

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