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
How to Set a Maximum Height With Wrap Content in Android
How to Get File Extension from Content Type
How to Override Spring Data JPA Repository Base Methods
Safely Generate Random Numbers Between Some Range in Java
Most Efficient Solution for Reading Clob to String, and String to Clob in Java
How to Specify the Path for Getresourceasstream() Method in Java
Parsing the Nested Json Array Using Jackson Library in Java
How to Execute SQL Script File in Java
Reading Only the Integers from a Txt File and Adding the Value Up for Each Found
How to Split a Huge Zip File into Multiple Volumes
Java Generics Incompatible Types (No Instance(S) of Type Variable(S) Exist)
Getting Url Parameter in Java and Extract a Specific Text from That Url
Spring Security 401 Unauthorized Even With Permitall
How to Change Background Colour to Specific Viewholder Items in a Recycleview
Password Validate 8 Digits, Contains Upper, Lowercase, and a Special Character