一:jar包方式启动(使用spring boot内置的tomcat运行,不需要外置tomcat )
1.打jar包
打包完成后 在Building jar后面就是打包完成后jar存放的位置,然后jar包所在的位置进入cmd(或者把jar放到自己想要的目录)
执行:java -jar jar包名称即可
$ nohup java -jar test.jar >temp.txt &
//这种方法会把日志文件输入到你指定的文件中,没有则会自动创建。进程会在后台运行。
在linux下运行:(该部分为转载)
二:Tomcat方式启动
1.修改pom文件:添加或修改为<packaging>war</packaging>
2.修改SpringBoot启动类:继承SpringBootServletInitializer
3.打包
4将war包放到tomcat的webapps下,启动tomcat即可
为了方便多端运行和部署(开发、测试、生产)我们可以再application.yml中添加
spring:
profiles:
active: @profile.active@
然后在pom.xml中添加如下配置
<profiles>
<profile>
<id>dev</id>
<properties>
<profile.active>dev</profile.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<profile.active>test</profile.active>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profile.active>prod</profile.active>
</properties>
</profile>
</profiles>
当我们在打包前,勾选需要的配置项目,然后点击package即可