Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I extract a spring boot executable jar?

spring boot project, build as a executable jar, but I found cannot extract the executable jar, e.g.

jar xvf spring-boot-foo-0.0.1-SNAPSHOT.jar

nothing output. But when extract a normal jar, it is successful

jar xvf mysql-connector-java-5.1.38.jar
created: META-INF/
inflated: META-INF/MANIFEST.MF
created: META-INF/services/
...

why is this?

like image 432
zhuguowei Avatar asked Jun 13 '16 06:06

zhuguowei


3 Answers

You can less your jar file and will find the following:

#!/bin/bash
#
#    .   ____          _            __ _ _
#   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
#  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
#   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
#    '  |____| .__|_| |_|_| |_\__, | / / / /
#   =========|_|==============|___/=/_/_/_/
#   :: Spring Boot Startup Script ::
#

That is, it's a bash file follow a jar, not a normal jar.

you can extract this file use : unzip spring-boot-foo-0.0.1-SNAPSHOT.jar

or set the executable flag of spring-boot-maven-plugin to false to make a normal jar file.

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <executable>false</executable>
    </configuration>
</plugin>
like image 80
peace0phmind Avatar answered Sep 24 '22 17:09

peace0phmind


I normally use 7zip to extract files on windows and it didn't work as well. Thanks to @peace0phmind I tried to open it with my Text editor (notepad++) and I saw that the content is a shell script followed by binary code.

I just removed all bash script lines, saved the file and now I can open it with 7zip.

like image 44
Eric Avatar answered Sep 21 '22 17:09

Eric


When using 7zip to open a Springboot executable jar you need to right-click on the .jar file and select the second 7zip option "Open Archive..." and select zip as format from the additional formats. Selecting "Open as archive" won't work.

like image 20
wowbagger Avatar answered Sep 22 '22 17:09

wowbagger