简体   繁体   中英

Eclipse import external JAR via system variable

i wish to add external JAR to my project without using Eclipse GUI. i have a system variable which hold the absolute path to the JAR file, how may i add it using java code.

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. This will result in an issue one way or the other. Like Snicolas said, its a very static way of doing things.

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:

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. Otherwise you could add it to your command lines for javac or java using the -classpath command line switch.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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