jenkins部署web(tomcat)项目3
一、准备环境
1. jenkins中安装deploy to container插件,重启jenkins生效
2. tomcat安装,配置:
tomcat目录\conf\tomcat-users.xml修改:
<role rolename="admin-gui"/> <role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <user username="jenkins" password="jenkins" roles="admin-gui,manager-gui,manager-script,manager-jmx,manager-status"/>
context.xml 去掉访问限制:tomcat\webapps\manager\META-INF\context.xml
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" 修改为 allow="^.*$"
解决 war包过大无法上传:tomcat/webapps/manager/WEB-INF/web.xml
<multipart-config>
<!-- 500MB max -->
<max-file-size>524288000</max-file-size>
<max-request-size>524288000</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
访问http://localhost:8080

输入用户名和密码:jenkins/jenkins

3. jenkins.war包放入tomcat安装目录/webapps下
4. 双击bin\startup.bat,启动tomcat
浏览器访问http://localhost:8080,Manager App

点击/jenkins,跳转到http://localhost:8080/jenkins/,可以访问到说明环境OK。8080是tomcat的端口号

二、部署web项目到tomcat
可以部署到本地tomcat或者是远程tomcat
新建Item->构建一个maven项目->确定








以上日志表示构建打包成war包,war包部署到本地tomcat成功。
部署成功,浏览器访问http://localhost:8080/manager/html,能看到maven_web

package com.itheima.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; public class MyServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.getRequestDispatcher("/hello.jsp").forward(request, response); } }
hello.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
hello maven
</body>
</html>
访问http://localhost:8080/maven_web/MyServlet,转发到hello.jsp:

浙公网安备 33010602011771号