【发布时间】:2016-06-23 09:22:36
【问题描述】:
我正在使用 springboot 应用程序。在使用java -jar 从命令行运行我的 app.jar 时,我收到以下错误
java.io.FileNotFoundException: C:\MyApp.jar!\lib\jackson-databind-2.6.5.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)
...
java.io.FileNotFoundException: C:\MyApp.jar!\lib\jackson-annotations-2.6.5.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.impetus.annovention.Discoverer.getResourceIterator(Discoverer.java:298)
at com.impetus.annovention.Discoverer.discover(Discoverer.java:142)
这些错误,我得到了多个 jar,尽管这些 jar 在 Spring boot fat jar 下的 lib 文件夹中可用。
现在,要解决这个问题,我可以使用requiresUnpack,如下所示。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${version-spring-boot}</version>
<configuration>
<requiresUnpack>
<dependency>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
</dependency>
<dependency>
<groupId>yyy</groupId>
<artifactId>yyy</artifactId>
</dependency>
</requiresUnpack>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
现在,这种方式的问题是针对我所有的 jars,我已将它们一一添加到我的 requiresUnpack 标记中。
但我正在寻找一些通用的方法来做到这一点。就像某个班轮可以解决所有这些问题。SO,有什么办法可以做到吗?
已编辑:添加我正在使用的其他插件...
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<configuration>
<defaultOutputDirectory>
${project.build.directory}/generated-sources
</defaultOutputDirectory>
<processors>
<processor>org.mapstruct.ap.MappingProcessor</processor>
</processors>
</configuration>
<executions>
<execution>
<id>process</id>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.0.0.CR1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
这 2 个插件是我用于 Mapstruct 的。
【问题讨论】:
-
你能发布更多你的 pom,比如你拥有的所有插件吗?
-
为什么不使用jackson lib的经典依赖?
-
不仅仅是杰克逊。有很多罐子我得到这样的。jackson-databind-2.6.5.jar jackson-annotations-2.6.5.jar json-patch-1.7.jar jackson-coreutils-1.6.jar msg-simple-1.1.jar btf -1.2.jar commons-rql-1.0.1.jar guava-18.0.jar c3p0-0.9.1.1.jar ... ...等等
-
抱歉重复我的问题,但为什么不使用经典依赖,为什么使用重新打包?
-
@MickaëlB 好的,我明白了……那我应该在目标中写什么?可以给我看看吗?
标签: java spring maven jar spring-boot