When executing a jar package from a command line or shell script under Linux, if the jar package does not refer to an external jar package, it is very easy to do so simply by using the following command:
Java-jar Test.jar #注意, if you do not specify the class that contains the main entry when you package the jar file, you need to add the class name, such as Com.test.HelloWord
But the actual application or production environment is simply impossible to have if the requirements are easy, if the jar needs to refer to the external jar package, then how to implement. You need to do some setup work, below is the implementation step:
One, use the jar package's configuration file to refer to the external jar package
1. Configure MANIFEST.MF Files
In the packaged jar, Meta-inf/manifest. MF This file lists the required external jar packages, and the contents of the file refer to the following:
manifest-version:1.0
Main-class:xx.json.sentjsont
Class-path:lib/commons-beanutils-1.9.2.jar Lib/commons-collections-3.2.2.jar Lib/commons-io-2.5.jar lib/ Commons-lang-2.6.jar Lib/commons-logging-1.2.jar Lib/ezmorph-1.0.6.jar Lib/httpclient-4.4.1.jar lib/ Httpcore-4.4.1.jar Lib/httpmime-4.4.1.jar Lib/jcl-over-slf4j-1.7.7.jar Lib/json-lib-2.4-jdk15.jar lib/ Noggit-0.6.jar Slf4j-api-1.7.7.jar Lib/solr-solrj-6.0.1.jar Lib/stax2-api-3.1.4.jar lib/ Woodstox-core-asl-4.4.1.jar Lib/zookeeper-3.4.6.jar
Precautions:
1 The path to the jar package after Class-path is the relative path under Liunx, and Windows needs to be modified to \.
2), the jar package behind the Class-path is separated by a space and must be in the same row.
2. Place all external jar packages under the Lib folder
In the folder where Xx.json.SentJsonT.jar is located, create a Lib folder and put all external jar packages under that folder.
3. Run the jar package
Java-jar sendjont.jar<span style= "White-space:pre" > </span> #一样的简单, not the same effect
second, the use of Java system environment variables
is to add all the external jar packages to the Class_path variable.