Andrew
Andrew

Reputation: 2813

Maven unzip spring boot executable jar

I need to unzip a spring boot executable jar as a part of my maven build.

I have tried two approaches, one using maven-dependency-plugin second - maven-antrun-plugin. Both plugins silently output nothing.

I went to debug maven-dependency-plugin and it seems like the library used to unzip the jar is not able to understand the executable jar format. I understand that spring-boot executable jar is not a regular archive (as it has a shell script embedded into it).

My question is, how do I extract files from the jar using maven?

I think a combination exec-maven-plugin and unzip command will work but this will make my build unportable, so I would like to avoid it.

EDIT: Here's the outup of antrun plugin:

    $ mvn antrun:run@unpack-jar
    ...
    [INFO]
    [INFO] --- maven-antrun-plugin:1.8:run (unpack-jar) @ subscriber-rpm ---
    [INFO] Executing tasks

    main:
        [unzip] Expanding: D:\path\conf.jar into D:\path\target\config
    [INFO] Executed tasks
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------

However, D:\path\target\config is not even created. maven-dependency plugin has a similar result.

Upvotes: 1

Views: 2311

Answers (1)

Anand Varkey Philips
Anand Varkey Philips

Reputation: 2075

What I think you should do is, You can use multiple profiles for each environments. Here is the documention. Here is an example from MKYONG.

https://www.mkyong.com/spring-boot/spring-boot-profiles-example/

If the configuration is in property file/yaml, you can modify it during runtime when you pass arguments like this:

/usr/bin/java -Dcom.webmethods.jms.clientIDSharing=true -jar myapp.jar

If you still prefer unwrapping jar, you may try replacing all shell script data with regex and then you get normal jar which can be opened in winzip or 7zip.( Your method would work now).

Upvotes: 1

Related Questions