Spring Boot java项目中的/ BOOT-INF / classes(没有这样的文件或目录)

问题描述 投票:3回答:1

为了制作一个我可以干净独立地启动的独立JAR,我遇到了涉及Jersey和我理想的胖JAR的问题。最终的jar将被移动到Docker镜像。

我得到的错误基本上是这样的:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.glassfish.jersey.server.ResourceConfig]: Factory method 'jerseyResourceConfig' threw exception; nested exception is org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.FileNotFoundException: /dir/myproject-1.0.0-SNAPSHOT.jar!/BOOT-INF/classes (No such file or directory)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 48 common frames omitted
Caused by: org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.FileNotFoundException: /dir/myproject/target/myproject-1.0.0-SNAPSHOT.jar!/BOOT-INF/classes (No such file or directory)
    at org.glassfish.jersey.server.internal.scanning.JarZipSchemeResourceFinderFactory.create(JarZipSchemeResourceFinderFactory.java:89)
    at org.glassfish.jersey.server.internal.scanning.JarZipSchemeResourceFinderFactory.create(JarZipSchemeResourceFinderFactory.java:65)
    at org.glassfish.jersey.server.internal.scanning.PackageNamesScanner.addResourceFinder(PackageNamesScanner.java:282)
    at org.glassfish.jersey.server.internal.scanning.PackageNamesScanner.init(PackageNamesScanner.java:198)
    at org.glassfish.jersey.server.internal.scanning.PackageNamesScanner.<init>(PackageNamesScanner.java:154)
    at org.glassfish.jersey.server.internal.scanning.PackageNamesScanner.<init>(PackageNamesScanner.java:110)
    at org.glassfish.jersey.server.ResourceConfig.packages(ResourceConfig.java:680)
    at org.glassfish.jersey.server.ResourceConfig.packages(ResourceConfig.java:660)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 49 common frames omitted
Caused by: java.io.FileNotFoundException: /dir/myproject/target/myproject-1.0.0-SNAPSHOT.jar!/BOOT-INF/classes (No such file or directory)

这是我的POM文件中的构建配置文件:

<profile>
    <id>d2</id>
    <activation>
        <activeByDefault>false</activeByDefault>
    </activation>
    <properties>
        <packaging.type>jar</packaging.type>
        <log.dir>logs</log.dir>
        <!-- updates bootstrap.properties -->
        <config.override.path>./conf</config.override.path>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <requiresUnpack>
                        <dependency>
                            <groupId>my.com</groupId>
                            <artifactId>myArtifact</artifactId>
                        </dependency>
                    </requiresUnpack>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

最后,以下是我正在使用的所有球衣依赖项:

org.springframework.boot:spring-boot-starter-jersey:jar:1.5.12.RELEASE:compile
|  |  +- org.glassfish.jersey.core:jersey-server:jar:2.25.1:compile
|  |  |  +- org.glassfish.jersey.core:jersey-client:jar:2.25.1:compile
|  |  |  +- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.25.1:compile
|  |  +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.25.1:compile
|  |  +- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.25.1:compile
|  |  +- org.glassfish.jersey.ext:jersey-spring3:jar:2.25.1:compile
|  |  \- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.25.1:compile
|  |     +- org.glassfish.jersey.ext:jersey-entity-filtering:jar:2.25.1:compile
................................................................................
|     |  +- org.glassfish.jersey.connectors:jersey-apache-connector:jar:2.17:compile
................................................................................
|  \- io.swagger:swagger-jersey2-jaxrs:jar:1.5.6:compile
|     +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.25.1:compile
|     |  +- org.glassfish.hk2.external:javax.inject:jar:2.5.0-b32:compile
|     |  \- org.glassfish.jersey.core:jersey-common:jar:2.25.1:compile
|     |     +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.25.1:compile
|     \- org.glassfish.jersey.media:jersey-media-multipart:jar:2.25.1:compile

我已经阅读了从这个SO question引用的所有来源。我被引导了几个github问题,Spring和Jersey显然已经修复了,但我仍在处理这些并发症。关于我的复杂性的独特之处在于,找不到的boot-inf / classes直接在我的jar中并引用项目本身。它没有抱怨一个不同的,依赖于jar,它抱怨项目自己的/ BOOT-INF /类。

上述SO问题中未提及的任何其他见解将非常有用!我发现在Docker中使用Java比使用任何其他堆栈(python-django和node-js)要难得多。如果需要更多信息,请与我们联系。

java maven docker spring-boot jersey-2.0
1个回答
1
投票

尝试添加以下插件

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> </plugin>

阅读更多关于这个https://maven.apache.org/plugins/maven-shade-plugin/

© www.soinside.com 2019 - 2024. All rights reserved.