linux服务器中解压与打包jar文件

  linux服务器中所部属的很多服务中,有相当一部分是jar文件,在设计这些程序的过程中,关键信息有相当一部分都是放在配置文件中,如何在服务器通过解压与压缩jar文件中的配置文件来修改关键信息呢?这里介绍jar文件的解压与压缩。

  解压:

[xxx@application01 bfd_test]$ ll
total 16
drwxr-xr-x 2 root root 4096 Oct 24 11:00 lib
-rw-r--r-- 1 root root 5523 Oct 24 11:05 TestLinuxPackage-0.0.1-SNAPSHOT.jar
drwxr-xr-x 2 root root 4096 Oct 24 12:38 unpack
[xxx@application01 bfd_test]$ cd unpack/
[xxx@application01 unpack]$ sudo jar -xvf ../TestLinuxPackage-0.0.1-SNAPSHOT.jar 
extracted: test.properties
  created: META-INF/
  created: META-INF/maven/
  created: META-INF/maven/com.changjiang.test/
  created: META-INF/maven/com.changjiang.test/TestLinuxPackage/
extracted: META-INF/maven/com.changjiang.test/TestLinuxPackage/pom.xml
extracted: META-INF/maven/com.changjiang.test/TestLinuxPackage/pom.properties
extracted: META-INF/MANIFEST.MF
  created: com/
  created: com/changjiang/
  created: com/changjiang/test/
  created: com/changjiang/test/TestLinuxPackage/
extracted: com/changjiang/test/TestLinuxPackage/App.class
[xxx@application01 unpack]$ ll
total 12
drwxr-xr-x 3 root root 4096 Oct 24 10:56 com
drwxr-xr-x 3 root root 4096 Oct 24 10:58 META-INF
-rw-r--r-- 1 root root   26 Oct 24 11:04 test.properties

  修改test.properties中的信息:

[xxx@application01 unpack]$ ll
total 12
drwxr-xr-x 3 root root 4096 Oct 24 10:56 com
drwxr-xr-x 3 root root 4096 Oct 24 10:58 META-INF
-rw-r--r-- 1 root root   26 Oct 24 11:04 test.properties
[xxx@application01 unpack]$ clear
[xxx@application01 unpack]$ cat test.properties
name=bruce
password=321
[xxx@application01 unpack]$ sudo sed -i "s/321/password/g" test.properties
[xxx@application01 unpack]$ cat test.properties
name=bruce
password=password

  打包当前目录下所有的文件到jar文件中:

[xxx@application01 unpack]$ ll
total 12
drwxr-xr-x 3 root root 4096 Oct 24 10:56 com
drwxr-xr-x 3 root root 4096 Oct 24 10:58 META-INF
-rw-r--r-- 1 root root   31 Oct 24 12:55 test.properties
[xxx@application01 unpack]$ sudo jar -cvfM0 Test.jar ./
adding: test.properties(in = 31) (out= 31)(stored 0%)
adding: META-INF/(in = 0) (out= 0)(stored 0%)
adding: META-INF/maven/(in = 0) (out= 0)(stored 0%)
adding: META-INF/maven/com.changjiang.test/(in = 0) (out= 0)(stored 0%)
adding: META-INF/maven/com.changjiang.test/TestLinuxPackage/(in = 0) (out= 0)(stored 0%)
adding: META-INF/maven/com.changjiang.test/TestLinuxPackage/pom.xml(in = 2114) (out= 2114)(stored 0%)
adding: META-INF/maven/com.changjiang.test/TestLinuxPackage/pom.properties(in = 134) (out= 134)(stored 0%)
adding: META-INF/MANIFEST.MF(in = 188) (out= 188)(stored 0%)
adding: com/(in = 0) (out= 0)(stored 0%)
adding: com/changjiang/(in = 0) (out= 0)(stored 0%)
adding: com/changjiang/test/(in = 0) (out= 0)(stored 0%)
adding: com/changjiang/test/TestLinuxPackage/(in = 0) (out= 0)(stored 0%)
adding: com/changjiang/test/TestLinuxPackage/App.class(in = 1257) (out= 1257)(stored 0%)
[xxx@application01 unpack]$ ll
total 20
drwxr-xr-x 3 root root 4096 Oct 24 10:56 com
drwxr-xr-x 3 root root 4096 Oct 24 10:58 META-INF
-rw-r--r-- 1 root root 5528 Oct 24 13:08 Test.jar
-rw-r--r-- 1 root root   31 Oct 24 12:55 test.properties

  测试下新打包的jar包是否能够正常运行:

[xxx@application01 unpack]$ sudo mv Test.jar ../Test.jar
[xxx@application01 unpack]$ cd ..
[xxx@application01 bfd_test]$ ll
total 16
drwxr-xr-x 2 root root 4096 Oct 24 11:00 lib
-rw-r--r-- 1 root root 5528 Oct 24 13:08 Test.jar
drwxr-xr-x 4 root root 4096 Oct 24 13:09 unpack
[xxx@application01 bfd_test]$ sudo java -jar Test.jar 
bruce
password
[xxx@application01 bfd_test]$ 

转载于:https://www.cnblogs.com/bruceChan0018/p/5992557.html

你可能感兴趣的:(linux服务器中解压与打包jar文件)