最近在做springboot的项目,发现springboot部署的方式还是比较特别的。
因为springboot 内置了tomcat,所以我们只要把它打成jar包即可运行。
下面就说一说jar包运行的方式:
1.单模块项目打包:
pom.xml文件里加入spring-boot-starter-tomcat依赖与spring-boot-maven-plugin插件。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<build>
<plugins>
<!-- springboot 打包的插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 打包的类型,这里是你的项目主类-->
<mainClass>com.cesgroup.eurekaServerDemo.EurekaServerDemoApplication</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
然后到路径目录下 运行:mvn clean package -DskipTests(-DskipTests是忽略单元测试,你也可以打包上去)。
你会发现 target\ 路径下已经生成了xxx.jar,双击运行即可启动项目。
其他启动方法:
到路径目录下 java -jar xxx.jar
或者后台运行的话就 nohup java -jar xxx.jar &
2.多模块项目打包:
pom.xml文件里同样的引入spring-boot-starter-tomcat依赖与spring-boot-maven-plugin插件。同上
因为是多模块,你要把其他模块引入到所打包的模块中(一般都是web模块)。
<dependency>
<groupId>com.cesgroup.zw.auth</groupId>
<artifactId>auth-center-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cesgroup.zw.auth</groupId>
<artifactId>auth-center-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cesgroup.zw.auth</groupId>
<artifactId>auth-center-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
然后这里的主类一定是在你所打包的模块里。
<configuration>
<!-- 打包的类型 -->
<mainClass>com.cesgroup.zw.WebApplication</mainClass>
<layout>ZIP</layout>
</configuration>
其余同上,大功告成!!!
所有评论(0)