Run command specifies packet java -jar external dependencies jar jar package linxux or windows

1. 生成 jar 包: sh hello.jar jar.sh

[chenquan@hostuser tartest]$ cat jar.sh 

jar -cvf0m ${1} ./META-INF/MANIFEST.MF .
[chenquan@hostuser tartest]$ ls META-INF/
MANIFEST.MF
[chenquan@hostuser tartest]$ ls test/
SignNatureTest.class
[chenquan@hostuser tartest]$ cat META-INF/MANIFEST.MF 
Manifest-Version: 1.0
Main-Class: test.SignNatureTest

[chenquan@hostuser tartest]

 2. Run the jar jar achieve external dependencies:

Prepared in the previous step moves into the jar package generated externally dependent jar libs directory or with the same level directory can lib,

java -jar -Djava.ext.dirs=./libs   ${i}
If, within libs, command -Djava.ext.dirs = parameter ./ if the resulting jar libs with the same level so instead ./libs meaning to tell my jar dependent jar package jar package relative to the position I want to be executed where is it
[chenquan@hostuser tests]$ ll
total 12
-rw-rw-r--. 1 chenquan chenquan 3188 Aug  4 12:06 foo.jar
-rw-rw-r--. 1 chenquan chenquan 3254 Aug  4 12:23 hello.jar
drwxr-xr-x. 4 chenquan chenquan  135 Aug  4 12:14 libs
-rwxrwxrwx. 1 chenquan chenquan  104 Aug  4 12:36 start.sh
[chenquan@hostuser tests]$ ls libs/
commons-codec-1.12.jar  commons-lang3-3.9.jar  setup.sh  SignNatureTest.java  tartest  test
[chenquan@hostuser tests]$ cat start.sh 
#!/bin/bash
for i in "$@"
do
 java -jar -Djava.ext.dirs=./libs ${i}
 echo "excuting ${i} res is:"
done

[chenquan@hostuser tests]$ 

The results, and here I am lazy to write sh files do not always knock again execute the command:

[chenquan@hostuser tests]$ sh start.sh hello.jar foo.jar
&k1=values1&k2=33
MD5string is: 832c599beef71cce2ca7e3953b4dc5fb2019-08-04 12:50:20excuting hello.jar res is:
&k1=values1&k2=33
MD5string is: 832c599beef71cce2ca7e3953b4dc5fb2019-08-04 12:50:21excuting foo.jar res is:
[chenquan@hostuser tests]$

 Supplementary: Classpath

  • Class-Path is set  . to declare the directory from which to start to find the location of all references to the class where the jar package

 

Guess you like

Origin www.cnblogs.com/SunshineKimi/p/11297883.html