最近在做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>

其余同上,大功告成!!!

转载于:https://www.cnblogs.com/codingdong/p/9846360.html

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐