springboot打成jar包后無法解壓
Springboot打出來的jar,用壓縮工具解壓報錯。Why? 先說解決辦法。
1、解決辦法
executable屬性導致的,屬性改成false后重新打包,就可以解壓
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
那么,executable設置成true作用是什么呢?為什么設置成true就無法解壓呢?
2、executable設置成true作用
一般情況下,我們運行jar的方式為:
java -jar xxx.jar
但如果你想在unix/linux上,像執行某個sh/服務那樣運行jar,就需要把你的app打包成executable的jar。
官方解釋:
In addition to running Spring Boot applications by using
java -jar, it is also possible to make fully executable applications for Unix systems. A fully executable jar can be executed like any other executable binary or it can be registered withinit.dorsystemd. This makes it very easy to install and manage Spring Boot applications in common production environments.
【A fully executable jar】就是通過前面提到的,打包時把executable設置為true。
3、無法解壓的原因分析
完全可執行 的 jar/war 在文件前面嵌入了個 額外的腳本,這就使得有些命令會執行失敗,比如 jar -xf 等。
這就是為什么解壓工具無法解壓的原因。
所以,如果你的jar是通過【java -jar】執行、或 放在servlet容器中執行,那么建議將executable設置為false。
Fully executable jars work by embedding an extra script at the front of the file. Currently, some tools do not accept this format, so you may not always be able to use this technique. For example,
jar -xfmay silently fail to extract a jar or war that has been made fully executable. It is recommended that you make your jar or war fully executable only if you intend to execute it directly, rather than running it withjava -jaror deploying it to a servlet container.
