Getting “Unable to open nested compressed entry” when making use of WarLauncher for executing a war file outside of servlet container

Question!

I am implementing a war file which should support execution in two different ways:

  1. Inside Servlet Container - by deploying it in Tomcat or Jetty.
  2. Outside Servlet Container - executing it from command prompt and not using any embedded servlet container. This is required to be supported as part of the war file.

I found Spring Boot Loader component more relevant for fulfilling #2. I tried using it manually before integrating it with Maven. I followed the section - 'WAR file structure' as mentioned as per this documentation. Refer to section 'WAR file structure'.

I followed the following steps. I created the war file. I unzipped it and then added all the spring boot loader class files at its root. I added appropriate entries to the manifest file for making the war executable. Then zipped it and renamed back it back to the original war file. When I executed it with command - Java -jar mywar.war, it failed with the following exception:

java.lang.IllegalStateException: Unable to open nested compressed entry WEB-INF/lib/spring-core-3.1.2.RELEASE.jar
    at org.springframework.boot.loader.jar.JarFile.getNestedJarFileFromFileEntry(JarFile.java:330)
    at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:305)
    at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:87)
    at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:74)
    at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:78)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:52)
    at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:79)

It is giving error not only for specific jar but for all jar files. I guess, it will also fail when I automate the above steps with Maven.

Thanks.



Answers

There are some restrictions with the underlying ZIP file format that make it impossible for the WarLauncher (and friends) to load resources from nested compressed archives. However you were building your WAR file you would need to re-do that step and ensure that the nested JARs are not compressed. Then it should work. (And if you use default settings for a Maven WAR build it would also work.)

By : Dave Syer


This video can help you solving your question :)
By: admin