Sets a jar package in a directory into Classpath and executes a jar file __jar

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.