java部署
2025/10/30小于 1 分钟约 201 字
简介
1. 背景:springboot后端 + vue3 、vite前端应用 捆绑创建建议admin项目
- 下载jre 临时运行环境
https://yuanbao.tencent.com/chat/naQivTmsDa?chatMode=temp
https://adoptium.net/zh-CN/temurin/releases?version=25&mode=filter&os=any&arch=any- 目录结构
my-app/
├── jre/ # 便携版JRE
├── app.jar # 包含前端的Spring Boot应用
├── start.bat
└── stop.bat- 后端放置前端项目放行静态目录
server:
port: 8080
spring:
web:
resources:
static-locations: classpath:/static/
mvc:
static-path-pattern: /**@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/");
}
@Controller
public static class FrontendController {
@RequestMapping(value = "{path:^(?!api|static).*}/**")
public String forward() {
return "forward:/index.html";
}
}
}- 启动脚本
@echo off
chcp 65001 >nul
title MyApp
REM 如果jre目录存在则使用,否则尝试直接运行(需要系统Java)
if exist jre (
jre\bin\java.exe -jar app.jar
) else (
java -jar app.jar
)