1

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.

Andrew
  • 2,663
  • 6
  • 28
  • 50
  • What errors are you getting with the dependency plugin ? Do you need to repackage after you've unzipped ? – PaulNUK Jun 19 '17 at 07:57
  • @PanulNUK there are no errors, dependency plugin is not able to see the contents of the jar at all. I don't think re-packaging is related to the question, but yes, I do re-package the extracted files afterwards, with rpm plugin. – Andrew Jun 19 '17 at 08:57
  • Why are you even extracting it? Feels like you are doing something you shouldn't be doing in the first place. – M. Deinum Jun 19 '17 at 10:37
  • I need to extract a property file, so that I can modify the configuration without having to reassemble the jar. – Andrew Jun 19 '17 at 10:57

1 Answers1

1

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).

Anand Varkey Philips
  • 1,811
  • 26
  • 41