我使用spring引導編寫了一個REST API,它使用了一些外部庫,這些庫通過依賴包含在我的pom.xml中。 如果我通過mvn spring-boot:運行在IntelliJ中啓動項目,一切正常,但如果我嘗試通過mvn包將所有內容打包到罐子中,除了spring-boot的所有外部依賴關係cals都會丟失。但是,相應的jar文件被複制到jar的lib文件夾中。 所以,如果我開始罐子一切工作得很好(回答的GetRequest的等),但只要我想初始化類型的變量FFmpegFrameGrabber(這是從bytedeco)我得到一個的NoClassDefFoundErrorNoClassDefFoundError spring boot maven
我POM看起來如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>spring-boot-test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.7.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
的genrerated罐(它的一部分)的結構:
罐
+你好
+ LIB
+ META-INF
+組織
---- + springframework的
---- +這裏shoould是bytedeco(?)
在此先感謝
編輯:最小(不)工作示例
package hello;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
String path = "D:\\TestVideos\\1\\original.mp4";
FFmpegFrameGrabber frameGrabber;
System.out.println("Starting Frame Grabber for: " + path);
frameGrabber = new FFmpegFrameGrabber(path);
try {
frameGrabber.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "Greetings from Spring Boot! Opening: " + path;
}
}
而且Application.java
package hello;
import java.util.Arrays;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}
這是直接從春季啓動教程。 坦克再次
我不熟悉bytedeco,但它的罐子還應該在你的JAR的'lib'文件夾及其所有類應提供。也許它做了不尋常的事情?你能提供一個能夠再現問題的小樣本嗎? –
它是ffmpeg的hava包裝。所有的ffmpeg jar都在libfolder中,但是在適當的地方沒有classfiles。 – TheElk