19

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?

4
  • 1
    Well open up the spring boot jar in your favorite zip tool. Can you? Is there anything in it?
    – Gimby
    Commented Jun 13, 2016 at 6:47
  • Yeah, unzip could extract it. but unizp could extract all jar file, not only spring boot executable jar.
    – zhuguowei
    Commented Jun 13, 2016 at 7:48
  • Winzip won't co-operate. Gives me Error: central directory not found.
    – Adam
    Commented Jul 20, 2017 at 10:40
  • @zhuguowei What happens when you unzip boot.jar that you don't like?
    – Adam
    Commented Jul 20, 2017 at 11:32

5 Answers 5

39

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>
4
  • 1
    how do they do that? What can I search for to learn more about this?
    – mdo123
    Commented Jul 5, 2017 at 21:30
  • It's a minor issue for me that you can't give Stack Overflow half-votes. You only answered half the question. And since you have only got 1 point rep, I'm not going to down-vote you and take it away, the karma would get me. It would ruin my peace 0ph mind.
    – Adam
    Commented Jul 20, 2017 at 10:36
  • I had to open the JAR in VI and delete the shell script at the top leaving everything after the exit command. Then unzip spring-boot-foo-0.0.1-SNAPSHOT.jar worked. Commented Nov 17, 2018 at 9:27
  • Change executable tag to false worked for me, thanks Commented Jul 31, 2020 at 16:27
17

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.

15

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.

0

Upgrade to Spring boot 2.6.7 and create a executable jar using gradle bootJar task. Now you can extract the jar eventhough it is executable.

Not sure if this is a bug in Spring boot 2.6.x

I tried with Spring boot version 2.6.7, Spring cloud version 2021.0.0, gradle 6.9.0

I am unable to restrict the jar from extracting it using any standard zip archive tools.

0

unzip will work because it is not a .tar archive file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.