How to Unpackage and Repackage a War File

How to extract .war files in java? ZIP vs JAR

If you look at the JarFile API you'll see that it's a subclass of the ZipFile class.

The jar-specific classes mostly just add jar-specific functionality, like direct support for manifest file attributes and so on.

It's OOP "in action"; since jar files are zip files, the jar classes can use zip functionality and provide additional utility.

Unpack WAR Is Not Unpacking

There is apparently a problem with the creation of the *.war dependency. It is first created with maven-war-plugin:war, and then repackaged with the spring-boot-maven-plugin:repackage. Unzipping the war from the command line succeeds, but produces a warning:

$ unzip myapp-war-0.0.1-SNAPSHOT.war
Archive: myapp-war-0.0.1-SNAPSHOT.war
warning [myapp-war-0.0.1-SNAPSHOT.war]: 7318 extra bytes at beginning or within zipfile

If I configure spring-boot-maven-plugin:repackage to disable the prepending of an executable *nix launch script to the war, maven-dependency-plugin:unpack works as expected:

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>false</executable>
</configuration>
</plugin>

How could I repack a jar file with all of its dependencies?

Have a look at jar jar. It sounds like it will do what you need.

Docker tomcat edit expanded war files

I am not sure exactly how you would achieve it with docker or anything else, as i dont see anyway to ask tomcat to just expand the war before it actually starts. But as per standard practices its not a good idea to explode a war and tweak the contents. It kills the entire purpose of making a war.

Rather you should make changes to the app to read configuration from << TOMCAT_HOME >>/conf.

If you achieve this the only thing you will need to tell Docker is to ADD your configuration file to the containers tomcat conf folder.

Or if it is a must for you to tamper with war file this is what you can do:
Explode the war manually (or by script) on your build machine and instead of adding war directly to the docker image, map the folder.
Something like this

ADD ./target/app-0.1.0.BUILD-SNAPSHOT /var/lib/jetty/webapps/ROOT.

And then manually add all your files to desired destinations.

ADD login.jsp /var/lib/jetty/webapps/ROOT/Webapps, so on and so forth.



Related Topics



Leave a reply



Submit