栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot+VUE 使用thinJar方式部署:gradle依赖的jar文件放在 /lib下,VUE前端页面放在jar之外 /static下

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot+VUE 使用thinJar方式部署:gradle依赖的jar文件放在 /lib下,VUE前端页面放在jar之外 /static下

部署目录如下:

1.在WebMvcConfigurer 配置静态资源映射地址

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    //允许访问静态资源,支持classpath:/static/ 及 jar的同级目录/static下
    String fileDir = "file:"+System.getProperties().getProperty("user.dir")+"/static/";
    registry.addResourceHandler("
@GetMapping({"/", "/index"})
public ModelAndView index() {
    return new ModelAndView("index.html");
}

4. 后端 jar分离部署,将springboot项目依赖第三方jar放在 /lib 下

我使用的是gradle,build.gradle 配置如下

plugins {
    id 'java'
}

group 'com.geline.cloud'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'cn.hutool:hutool-all:5.7.6'
    implementation 'org.springframework.boot:spring-boot-starter-logging'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-aop'
}

task clearJar(type: Delete) {
    delete "$buildDir\libs\lib"
}
task copyJar(type: Copy, dependsOn: 'clearJar') {
    from configurations.compileClasspath
    into "$buildDir\libs\lib"
}
bootJar.enabled = true
bootJar {
    excludes = ["*.jar"]
    dependsOn clearJar
    dependsOn copyJar
    manifest {
        attributes "Manifest-Version": 1.0, 'Class-Path': configurations.compileClasspath.files.collect { "lib/$it.name" }.join(' ')
    }
}

jar {
    enabled(true)
    from('src/main/java'){
        include '**/*.xml'
    }
}

publishing {
    repositories {
        maven {
            name = 'localRepo'
            url = "file://${buildDir}/repo"
        }
    }
    publications {
        myApp(MavenPublication) {
            from components.java
        }
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/888645.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号