One way to do this is to set the classpath in the Mainfest file in the jar file you want to execute. It's easy to write the wrong name. Add the. jar file in the delete Lib folder at any time because you need to modify the Mainfest file every time you add a deletion classpath
There's a lot of it. How to set the jar package for a directory to classpath, but if you finish setting up the Java-jar command to execute a jar package, the previous setting is blocked by default.
The solution is to set the jar package to be executed into the classpath, and then execute the normal Java command to run the class file in the jar package
For example, a Run.bat file is produced in Windows, which reads:
SetLocal enabledelayedexpansion
Set classpath=.
For%%i in (' Lib/*.jar ') do SET classpath=! classpath!; %%i//Here must be! Not%
Set classpath=%classpath%; Josp.jar//This is the jar file I want to execute
Echo%classpath%
JAVA-CP%classpath% jospserver.ospserver 192.168.100.206 7 Chenyi//jospserver is the package name, and Ospserver is the class name. The following are the running parameters I need for the program
In Linux, make a shell command, run.sh, which reads:
#!/bin/sh
#获取当前目录
Pwd= ' PWD '
Classpath= $PWD/josp.jar: "$CLASSPATH"
For i in Lib/*.jar;
Do classpath= $PWD/$i: "$CLASSPATH";
Done
Export classpath=.: $CLASSPATH
JAVA-CP $CLASSPATH jospserver.ospserver 192.168.100.206 7 Chenyi
This eliminates the need to set the classpath parameters in the mainfest in the Josp.jar file, and you can add and remove the. jar files from the Lib folder as needed without modifying the mainfest