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

时光怂恿深爱的人放手 提交于 2020-01-03 05:15:14

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/29847508/running-jar-does-not-use-jars-from-lib-when-packaged-with-mvn-clean-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!