spring boot项目打war包
1.如果有本地依赖,添加本地依赖到maven
<!--lib目录下的jar包--> <dependency> <groupId>com.dm</groupId> <artifactId>dmjdbc</artifactId> <version>1.7.0</version> <scope>system</scope> <systemPath>${project.basedir}/lib/Dm7JdbcDriver17.jar</systemPath> </dependency> <!--添加驱动,将本地jar包打到war包中--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> <executions> <execution> <id>copy-dependencies</id> <phase>compile</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory> <includeScope>system</includeScope> </configuration> </execution> </executions> </plugin>
2.pom文件将默认jar打包方式改为war
<packaging>war</packaging>
3.pom文件中配置外部Tomcat
<!--配置外部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>
4.添加web方式启动类
public class EvalServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(EvalApplication.class); } public static void main(String[] args) { } }
5.打包和访问
打包命令:clean package -Dmaven.test.skip=true(打jar包命令为clean install-Dmaven.test.skip=true)
打好的war包在target目录下,将war包复制到Tomcat的webapps下,在Tomcat的bin目录下启动Tomcat(startup.bat/sh)
访问:浏览器访问:ip:8080/项目名 (pom文件通过<name>项目名</name>来配置项目名)