到Jenkins
中新建一个项目名叫web_demo_freestyle
然后拉取代码
然后编译打包
echo "——编译打包开始——"
mvn clean package
echo "——编译打包结束——"
完成
安装Deploy to container
插件
安装完成
回到web_demo_freestyle
项目的配置
增加构建后操作步骤->
点击Deploy war/ear to a container
输入war
包目录
target/*.war
添加一个凭据
输入用户名tomcat
和密码tomcat
输入tomcat
服务器地址,保存
然后构建,成功后就是这样了
我们发现已经能访问了
我们更改一下代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<body>
<h2>Hello jenkins!</h2>
<div class="yesMyTime">
当前时间:
<span id="date"></span>
<span id="time"></span>
</div>
<script type="application/javascript">
window.onload = function () {
setTime();
};
function getTime() {
let week = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
let localToday = "";
let d = new Date();
// console.log(d)
localToday =
d.getFullYear() +
"年" +
(d.getMonth() + 1) +
"月" +
d.getDate() +
"日";
let time = "";
let hh = d.getHours(); //时
let mm = d.getMinutes(); //分
let ss = d.getSeconds(); //秒
if (hh < 10) time += "0";
time += hh + ":";
if (mm < 10) time += "0";
time += mm + ":";
if (ss < 10) time += "0";
time += ss;
return {
0: localToday,
1: week[d.getDay()],
2: time
};
}
let timer = null;
function setTime() {
if (timer !== null) {
clearTimeout(timer);
}
setTimeout(function () {
document.getElementById("date").innerHTML=getTime()[0];
document.getElementById("time").innerHTML=getTime()[1] + " " + getTime()[2];
setTime();
}, 1000);
}
</script>
</body>
</html>
然后push
然后回到jenkins进行构建
成功后刷新我们的tomcat
可以看到我们的更改