运行 当用 mvn clean package 打包时,Jar 不使用来自 lib/* 的 jar

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

我有spring-boot应用,先打包成jar 使用

mvn clean package

我正在尝试 运行 它作为

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

但由于以下错误而失败。

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 文件 eureka-client-1.1。147.jar 存在于 jar 内的 lib 文件夹中,MANIFEST.MF 也有它的条目。

求推荐。

问题是由于 Jersey 的局限性导致的——它无法处理嵌套的 JAR 文件。您需要将 Boot 配置为在您的应用程序启动时自动解压缩任何包含 JAX-RS 资源的 JAR,例如:

<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>