Reputation: 16931
I know there are a dozen questions like this out there but I didn't find any of their solutions suitable for my case!
So, I'm trying to pack a jar file for a Spring-Boot project using Maven. I've created the whole project using IntelliJ IDEA and it runs under IDE. In order to build the package, I use mvn package
from the command line.
The generated .jar file can be run on my development machine too but when I copy the .jar file to some raw docker container, it gives out the following error:
Exception in thread "main" java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/lucene-highlighter-5.4.1.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file
And here's my pom.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
</project>
Upvotes: 4
Views: 17328
Reputation: 331
It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file
It just means that we should use no compression by a command like this:
jar -uvf0 example_app.war DIR_TO_ADD
Where "0" means that no compression will be used.
See "0" options in: https://docs.oracle.com/javase/7/docs/technotes/tools/windows/jar.html#options
Such a way helped me to add the directory with files and run the java without errors like in the subject.
Upvotes: 3
Reputation: 954
I also faced this issue and tried the following way which worked well for me.
NOTE : Dont' extract and build new jar again. Simply extract and update existing jar with modified file.
For example, there is a jar namely myjar.jar in lab_directory
i) move to lab_directory and extract myjar.jar ( which has dir1/config.properties file )
ii) copy dir1 in extracted folder to lab_directory folder
iii) modify lab_directory/dir1/config.properties
iv) Run following command in lab_directory
jar -uf myjar.jar dir1/config.properties
That's it. Existing myjar.jar has been updated with modified config.properties file now.
Upvotes: 4
Reputation: 16931
As it turned out, it had nothing to do with Maven and/or Spring-Boot. In case someone else might face the same issue, here's what I've done that led to this problem:
As a part of my deployment process, I would unzip the jar file, revise the config.properties and zip it again. It seems for some reason (unknown to myself), the generated .jar file is not executable and leads to the mentioned error.
My workaround was not to uncompress the .jar file, instead just replace the config.properties with a single command, like zip ./project.jar ./config.properties
, while the project.jar is already in the current path. This one works!
Upvotes: 4