[英]NoClassDefFoundError for Gradle fat jar with tests Spring Boot
[英]Spring boot, gradle, angularJS and a fat jar
我的spring-boot项目是这样的:
project
|__ build.gradle
|__ settings.gradle
|__ application
|__ library
|__ web
|__ application
|__ library
|__ web
应用程序包含main和一个实现WebMvcConfigurer的MvcConfig类:
@Configuration
public class MvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers (ResourceHandlerRegistry registry) {
String workingDirectory = System.getProperty("user.dir");
registry.addResourceHandler("/**")
.addResourceLocations("file:///" + workingDirectory + "/../web/dist/");
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html");
}
}
当我运行时:gradlew:application:bootRun =>一切正常。
我的Web目录是angularJS应用程序,而gulp则将其构建在dist目录中。 (我正在使用moowork节点和gulp gradle插件)
但是现在我想将我的所有应用程序放在一个用bootJar生成的胖罐中。
java -jar application.jar (will run all the app)
application.jar包含web.jar,其中包含dist目录中的所有内容。
gradlew:application:bootJar生成一个包含所有内容的jar(库,spring-boot网络),但是当我启动它时,找不到我的index.html
我知道我必须更改addResourceLocations参数,但是我需要一些帮助。 我已经尝试过(没有成功):
.addResourceLocations("classpath:/web/");
好吧,答案很简单:由于web.jar包含dist内部的所有内容,因此我只需要这样做:
.addResourceLocations("classpath:/");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.