首页 Tomcat教程tomcat实战案例:自动的应用部署

tomcat实战案例:手动的应用部署

tomcat实战案例: 应用部署实现基于WEB的管理

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

实战案例:自动的应用部署

1. 制作应用的war包文件

[root@centos8 ~]#ls /data/testapp2/
test.html  test.jsp
[root@centos8 ~]#cat /data/testapp2/test.html 
<h1>This is test html </h1>
[root@centos8 ~]#cat /data/testapp2/test.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>jsp例子</title>
</head>
<body>
后面的内容是服务器端动态生成字符串,最后拼接在一起
<%
out.println("hello jsp");
%>
</body>
</html>[root@centos8 ~]#cd /data/testapp2/

#生成war包文件
[root@centos8 testapp2]#jar cvf /data/testapp2.war *
added manifest
adding: test.html(in = 28) (out= 27)(deflated 3%)
adding: test.jsp(in = 329) (out= 275)(deflated 16%)
[root@centos8 testapp]#cd /data/testapp2/
[root@centos8 testapp]#ls
test.html  test.jsp
[root@centos8 testapp2]#cd /data/
[root@centos8 data]#ls
testapp  testapp.war
[root@centos8 data]#file testapp2.war
testapp.war: Java archive data (JAR)
[root@centos8 data]#chown tomcat.tomcat /data/testapp2.war

2、自动应用部署上面的war包

[root@centos8 tomcat]#pwd
/usr/local/tomcat
[root@centos8 tomcat]#ls webapps/
docs  examples  host-manager  manager  ROOT
[root@centos8 tomcat]#ls work/Catalina/localhost/
docs  examples  host-manager  manager  ROOT
[root@centos8 tomcat]#chown tomcat.tomcat /data/testapp2.war 
[root@centos8 tomcat]#cp -p /data/testapp2.war webapps/

#再次查看,tomcat将testapp.war自动解压缩
[root@centos8 tomcat]#ll webapps/
total 8
drwxr-x--- 15 tomcat tomcat 4096 Feb  9 11:02 docs
drwxr-x---  6 tomcat tomcat   83 Feb  9 11:02 examples
drwxr-x---  5 tomcat tomcat   87 Feb  9 11:02 host-manager
drwxr-x---  5 tomcat tomcat  103 Feb  9 11:02 manager
drwxr-x---  3 tomcat tomcat  300 Feb  9 19:59 ROOT
drwxr-x---  3 tomcat tomcat   55 Feb  9 20:14 testapp2
-rw-r--r--  1 tomcat tomcat  862 Feb  9 20:05 testapp2.war
[root@centos8 tomcat]#ll webapps/testapp2
total 8
drwxr-x--- 2 tomcat tomcat  44 Feb  9 20:14 META-INF
-rw-r----- 1 tomcat tomcat  28 Feb  9 20:03 test.html
-rw-r----- 1 tomcat tomcat 329 Aug 30 02:30 test.jsp

#work目录会自动生成对应的testapp的子目录,但目录内无内容
[root@centos8 tomcat]#tree work/Catalina/localhost/testapp/
work/Catalina/localhost/testapp2/

0 directories, 0 files

#访问jsp文件后,tomcat会自动将jsp转换和编译生成work目录下对应的java和class文件
[root@centos8 tomcat]#curl http://127.0.0.1:8080/testapp2/test.jsp

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>jsp例子</title>
</head>
<body>
后面的内容是服务器端动态生成字符串,最后拼接在一起
hello jsp

</body>
</html>[root@centos8 ttree work/Catalina/localhost/testapp2/
work/Catalina/localhost/testapp2/
└── org
    └── apache
        └── jsp
            ├── test_jsp.class
            └── test_jsp.java

3 directories, 2 files
[root@centos8 tomcat]#curl http://127.0.0.1:8080/testapp2/test.html
<h1>This is test html </h1>
[root@centos8 tomcat]#tree work/Catalina/localhost/testapp/
work/Catalina/localhost/testapp2/
└── org
    └── apache
        └── jsp
            ├── test_jsp.class
            └── test_jsp.java

3 directories, 2 files

#自动删除(反部署)
#[root@centos8 tomcat]#rm -f webapps/testapp2.war  
[root@centos8 tomcat]#ls webapps/
docs  examples  host-manager  manager  ROOT  testapp2
#过几秒再查看,发现testapp2目录也随之删除
[root@centos8 tomcat]#ls webapps/
docs  examples  host-manager  manager  ROOT
[root@centos8 tomcat]#ls webapps/
docs  examples  host-manager  manager  ROOT
[root@centos8 tomcat]#ls  work/Catalina/localhost/
docs  examples  host-manager  manager  ROOT

本文链接:https://www.yunweipai.com/35137.html

tomcat实战案例:手动的应用部署

tomcat实战案例: 应用部署实现基于WEB的管理

网友评论comments

发表回复

您的电子邮箱地址不会被公开。

暂无评论

Copyright © 2012-2022 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部