简体   繁体   中英

How to run a custom jar file copy to classpath command using java?

I have a jar file which I'm using to run as an application. However, every time I run my application I need to add -cp "jar name" to compile it and then run the java application.

How can I make a permanent change so that I don't have to use the command line commands for this task? Can I put that in certain lib location?

Note: I don't have to use any IDE. It has to be from a terminal.

Add your custom JAR in the CLASSPATH . Steps to setup and verify are available here: JAVA PATH & CLASSPATH

If you are on Linux/ Mac, add the following to your ~/.bash_profile

export CLASSPATH=$CLASSPATH:/path/to/jar

If you are on windows, use this..

set CLASSPATH=%CLASSPATH%;\path\to\jar

You can read more about it here and here

您可以将您的lib或其他jar复制到JAVA_HOME / lib / ext或系统变量CLASSPATH中的任何目录中

One more solution: extension libraries, put your jar into $JAVA_HOME/lib/ext

One needs to be careful - every java application will pick up this jar

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