系统设置->全局工具配置
Maven 配置
选择自已的setting配置文件
JDK 安装
指定自己的jdk目录
Git
指定自己的git,如果系统已经安装,会自动检测到
Maven
指定自己的maven目录
准备发布tomcat的war包
添加帮助类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class RenrenApplicationWeb extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(RenrenApplicationWeb.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(RenrenApplication.class);
}
}
pom依赖
provided指定tomcat相关jar包不会打包进war,使用容器的jar包
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
finalName指定war包的名称,也是容器的访问路径
<build>
<finalName>generator</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
tomcat配置
修改端口
修改apache-tomcat-8.5.34\conf\server.xml文件
这里把8080修改成了8089
<Connector port="8089" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
新增用户
修改apache-tomcat-8.5.34\conf\tomcat-users.xml文件
以下为tomcat内置的管理角色
Built-in Tomcat manager roles:
- manager-gui - allows access to the HTML GUI and the status pages
- manager-script - allows access to the HTTP API and the status pages
- manager-jmx - allows access to the JMX proxy and the status pages
- manager-status - allows access to the status pages only
新增用户tomcat_user并给他管理角色权限,这样jenkins才能把war包发布到tomcat容器中
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="tomcat_user" password="123456" roles="manager-gui,manager-script,manager-jmx,manager-status"/>
新建item并配置
构建一个maven项目
如果没有构建一个maven项目选项,请下载Maven Integration plugin
clean package -Dmaven.test.skip=true -P dev
指定模块构建
clean package -pl [groupId]:[artifactId] -am
至此部署完成,点击构建自动部署
访问http://localhost:8089/generator/