简体   繁体   English

弹簧靴,gradle,angularJS和一个胖子罐

[英]Spring boot, gradle, angularJS and a fat jar

My spring-boot project is like this: 我的spring-boot项目是这样的:

project
|__ build.gradle
|__ settings.gradle
   |__ application
   |__ library
   |__ web
|__ application
|__ library
|__ web

application contains the main and a MvcConfig class that implements WebMvcConfigurer: 应用程序包含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");
    }
}

When I run : gradlew :application:bootRun => everything works fine. 当我运行时:gradlew:application:bootRun =>一切正常。

My web directory is a angularJS application and gulp builds it in a dist repertory. 我的Web目录是angularJS应用程序,而gulp则将其构建在dist目录中。 (I'm using moowork node and gulp gradle plugin) (我正在使用moowork节点和gulp gradle插件)

But now I want to a have all my application in one fat jar generated with bootJar. 但是现在我想将我的所有应用程序放在一个用bootJar生成的胖罐中。

java -jar application.jar (will run all the app)

application.jar contains web.jar wich contains all that is inside the dist repertory. application.jar包含web.jar,其中包含dist目录中的所有内容。

gradlew :application:bootJar generates a jar with everything (library, spring-boot web) but when I launch it, it doesn't find my index.html gradlew:application:bootJar生成一个包含所有内容的jar(库,spring-boot网络),但是当我启动它时,找不到我的index.html

I know that I have to change the addResourceLocations arguments but I need some help to do it. 我知道我必须更改addResourceLocations参数,但是我需要一些帮助。 I have tried (without success): 我已经尝试过(没有成功):

.addResourceLocations("classpath:/web/");

好吧,答案很简单:由于web.jar包含dist内部的所有内容,因此我只需要这样做:

.addResourceLocations("classpath:/");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM