Search code examples
springspring-bootmaven-3netflixnetflix-eureka

Running Jar does not use jars from lib/* when packaged with mvn clean package


I have spring-boot application, which is first packaged to jar using

mvn clean package

I am trying to run it as

java -jar target/bootstep-0.0.1-SNAPSHOT.jar

But it fails due to following error.

2015-04-24 16:06:45.425  INFO 27324 --- [ost-startStop-1] c.s.j.api.core.PackagesResourceConfig    : Scanning for root resource and provider classes in the packages:
  com.netflix.discovery
  com.netflix.eureka
2015-04-24 16:06:45.470 ERROR 27324 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Exception starting filter servletContainer

com.sun.jersey.core.spi.scanning.ScannerException: IO error when scanning jar 
..
..
    at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\springbootproject\target\bootstep-0.0.1-SNAPSHOT.jar!\lib\eureka-client-1.1.147.jar (The system cannot find the path specified)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    at java.net.URL.openStream(Unknown Source)
    at com.sun.jersey.core.spi.scanning.uri.JarZipSchemeScanner.closing(JarZipSchemeScanner.java:123)
    at com.sun.jersey.core.spi.scanning.uri.JarZipSchemeScanner.scan(JarZipSchemeScanner.java:75)

Jar file eureka-client-1.1.147.jar is present in lib folder inside jar and MANIFEST.MF also has entry of it.

Please suggest.


Solution

  • The problem's due to a limitation in Jersey – it can't cope with nested JAR files. You need to configure Boot to automatically unpack any JARs containing JAX-RS resources when your app launches, for example:

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <requiresUnpack>
                <dependency>
                    <groupId>com.netflix.eureka</groupId>
                    <artifactId>eureka-core</artifactId>
                </dependency>
                <dependency>
                    <groupId>com.netflix.eureka</groupId>
                    <artifactId>eureka-client</artifactId>
                </dependency>
            </requiresUnpack>
        </configuration>
    </plugin>