spring boot项目,构建为可执行jar,但我发现无法提取可执行jar,例如。
jar xvf spring-boot-foo-0.0.1-SNAPSHOT.jar
没有输出。 但是当提取一个普通的jar时,它是成功的
jar xvf mysql-connector-java-5.1.38.jar
created: META-INF/
inflated: META-INF/MANIFEST.MF
created: META-INF/services/
...
为什么会这样?
答案 0 :(得分:16)
您可以less
您的jar文件,并找到以下内容:
#!/bin/bash
#
# . ____ _ __ _ _
# /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
# ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
# \\/ ___)| |_)| | | | | || (_| | ) ) ) )
# ' |____| .__|_| |_|_| |_\__, | / / / /
# =========|_|==============|___/=/_/_/_/
# :: Spring Boot Startup Script ::
#
也就是说,它是一个bash文件,跟随一个jar,而不是一个普通的jar。
您可以使用unzip spring-boot-foo-0.0.1-SNAPSHOT.jar
或将spring-boot-maven-plugin的可执行标志设置为false以生成普通的jar文件。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>false</executable>
</configuration>
</plugin>
答案 1 :(得分:6)
我通常使用7zip在Windows上提取文件,但它也不起作用。感谢@ peace0phmind,我尝试用我的文本编辑器(记事本++)打开它,我看到内容是一个shell脚本,后跟二进制代码。
我刚刚删除了所有bash脚本行,保存了文件,现在我可以用7zip打开它。
答案 2 :(得分:2)
使用7zip打开Springboot可执行jar时,需要右键单击.jar文件,然后选择第二个7zip选项“ Open Archive ...”,然后从其他格式中选择zip作为格式。 选择“以存档形式打开”无效。