maven打包springboot项目(war包和jar包)
maven项目pom.xml引入本地jar:
1.示例: dependency标签添加systemPath配置
<dependency> <groupId>com.kingbase8</groupId> <artifactId>kingbase8</artifactId> <version>8.6.0</version> <scope>system</scope> <systemPath>${project.basedir}/lib/kingbase8-8.6.0.jar</systemPath> </dependency>
2.在项目根路径下新建lib文件夹,存放外部jar
springboot打jar包:
1.pom.xml打包方式:<packaging>jar</packaging>
2.build配置
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <build>
3, pom.xml引入本地jar包,build配置
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <includeSystemScope>true</includeSystemScope> </configuration> </plugin> </plugins> </build>
springboot打war包:
- pom.xml去掉tomcat依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId>- <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>
- 添加tomcat依赖,scope为provided运行时
<!--打war的时候需要--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency>
-
pom.xml中打包方式改成war: <packaging>war</packaging>
- pom.xml中有引本地jar包的情况,build配置
<build> <finalName>包名称</finalName> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <webResources> <resource> <directory>${project.basedir}/lib</directory> <targetPath>WEB-INF/lib</targetPath> <includes> <includes>**/*.jar</includes> </includes> </resource> </webResources> </configuration><plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugin>
</plugins></build>
pom.xml中没有引外部jar(正常情况),bulid配置
<build> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId><configuration>
<warSourceExcludes>src/main/resources/**</warSourceExcludes>
<warName>包名称</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins> </build> - springboot启动类继承
SpringBootServletInitializer
重写configure
方法@SpringBootApplication public class AppApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(AppApplication .class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(AppApplication .class); } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端