1

After compiling my Spring Boot application with mvn clean install I am not being able to run the fat jar with java -jar target/myapplication-1.0.jar due to the following error:

java.io.IOException: Unable to open root Jar file 'war:file:/Users/coterobarros/git/repository/myapplication/target/myapplication-1.0.jar*/BOOT-INF/lib/spring-webmvc-5.3.1.jar'
...

Unzipping the application fat jar, the allegedly missing spring-webmvc-5.3.1.jar jar file can be found at BOOT-INF/lib/spring-webmvc-5.3.1.jar.

On the other hand, the application can be successfully run from Spring Tool Suite 4 IDE or issuing mvn spring-boot:run.

Notice an asterisk * between the fat jar path and the path to spring-webmvc-5.3.1.jar. I suppose this is the error, but I don't know where this symbol comes from.

Any Idea?

This is my pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.0-SNAPSHOT</version>
    <relativePath /> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.ofaraday</groupId>
  <artifactId>myapplication</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>
  <name>myapplication</name>
  <description>myapplication.com application</description>

  <properties>
    <java.version>14</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>

    <!-- To add custom properties to application.properties -->
    <!-- See https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#configuration-metadata-annotation-processor -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-configuration-processor</artifactId>
      <optional>true</optional>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

  <repositories>
    <repository>
      <id>spring-milestones</id>
      <name>Spring Milestones</name>
      <url>https://repo.spring.io/milestone</url>
    </repository>
    <repository>
      <id>spring-snapshots</id>
      <name>Spring Snapshots</name>
      <url>https://repo.spring.io/snapshot</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>spring-milestones</id>
      <name>Spring Milestones</name>
      <url>https://repo.spring.io/milestone</url>
    </pluginRepository>
    <pluginRepository>
      <id>spring-snapshots</id>
      <name>Spring Snapshots</name>
      <url>https://repo.spring.io/snapshot</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </pluginRepository>
  </pluginRepositories>
</project>
coterobarros
  • 941
  • 1
  • 16
  • 25
  • 2
    Why are you an old SNAPSHOT? I would strongly suggest to upgrade to the latest 2.4.x (or better 2.5.x) version of Spring Boot. Also you state you are running a `jar` but why is the path `war:file:`? That looks a but strange. It looks like you wanted to create a war (due to the fact the tomcat dependency is `provided` and the addition of the `tomcat-embed-jasper`). If the latter is your goal (the war) then use a war instead of a jar. – M. Deinum Nov 17 '21 at 15:14
  • I really don't know. I am very new to Spring Boot and simply considered I could exchange the original `war` by `jar` and that's all. May be I have to change something else? – coterobarros Nov 17 '21 at 15:17
  • No you cannot. Just use war as the packaging (and you still can run it with `java -jar name-of-war.war`. – M. Deinum Nov 17 '21 at 15:18
  • Thank you. I'll give it a try – coterobarros Nov 17 '21 at 15:18
  • No, the problem persists after going back to `war`. Now the error line is `java.io.IOException: Unable to open root Jar file 'war:file:/Users/coterobarros/git/repository/myapplication/target/myapplication-1.0.war*/WEB-INF/lib/spring-webmvc-5.3.1.jar'` – coterobarros Nov 17 '21 at 15:22
  • Is that asterisk an expected symbol? – coterobarros Nov 17 '21 at 15:23
  • 1
    Yup. Is the jar correct? Could be corrupted and hence not able to open it. You might want to clean your maven repository (and as stated I strongly suggest to upgrade Spring Boot to a proper version instead of a snapshot). – M. Deinum Nov 17 '21 at 15:24
  • I have updated maven several times, clean the project from the IDE, removed the `target` folder manually to recreate everything, remove the `~/.m2/repository` folder and re-downloaded maven... – coterobarros Nov 17 '21 at 15:26
  • Now installing a newer version of SB, as you recomended – coterobarros Nov 17 '21 at 15:26
  • Thanks a lot, Marten! I upgraded to 2.5.6 and the issue disappeared! – coterobarros Nov 17 '21 at 15:50

0 Answers0