Home > Blockchain >  Given all libraries extracted from a Fat Jar, how to rebuild the source code?
Given all libraries extracted from a Fat Jar, how to rebuild the source code?

Time:04-26

There is a Fat Jar, built with Spring Boot and Maven. Its internal structure can be explored, using enter image description here

The Fat Jar can execute successfully under JDK/JRE 1.8 as a standalone application. Using 7z, one can extract the Fat Jar and collect all libraries embedded in it.

I have the source code (Maven with POM.XML) that was used to build the Fat Jar, and I would like to modify it (no new additional library added). Put it simply, comment a few line of code, then recompile it (it will be again a Fat Jar).

Question: The problem is: when recompiling the source code (command: mvn package), one of repository is no longer accessible from Internet. Is there a definite way (step by step) to recompile? In theory, this should be possible as we already have all needed libraries to run the Jar (thanks to "Fat Jar" feature).

My Attempt:

  1. Extract the Fat Jar.
  2. Using mvn install:install-file -Dfile=<path-to-file> to install one by one library into local Maven repository (c:\Users\[username]\.m2\repository\). Then later, I can execute mvn package against the main source code, with the assumption that all libraries needed are available in the local Maven repo; thus, no need to fetch it from Internet.
  3. But I got a lot of problems, e.g. 'groupId' is missing.

CodePudding user response:

You need to install:install-file the missing libraries to your local repository and set the GAV (groupId, artifactId, version) correctly when installing it.

Generally, I would also check if there is an easier way to solve your problem than patching the library.

  • Related