栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java > Tomcat

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

Tomcat 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

1. 制作应用的war包文件

[root@centos8 ~]#ls /data/testapp2/
test.html  test.jsp
[root@centos8 ~]#cat /data/testapp2/test.html 
This is test html 
[root@centos8 ~]#cat /data/testapp2/test.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>



    
    jsp例子


后面的内容是服务器端动态生成字符串,最后拼接在一起
<%
out.println("hello jsp");
%>

[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




    
    jsp例子


后面的内容是服务器端动态生成字符串,最后拼接在一起
hello jsp


[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
This is test html 
[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
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/10409.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号