我正在使用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)
这些错误,我得到的是多个罐子,虽然这些罐子可以在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>
现在,问题出在我的所有罐子上,我已经在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>
这些,我用于Mapstruct的2个插件。
答案 0 :(得分:0)
正如我在评论中所说,为什么不使用经典的依赖关系,例如:
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.5</version>
</dependency>