tomcat部署web项目方法

2019-08-22  本文已影响0人  月沉眠love

原文链接:https://www.cnblogs.com/nananana/p/9387694.html

一、tomcat部署web项目之静态配置:

方法一:直接将为web项目放到webapps下:

如图所示:在webapps文件下,存放了一个html文件,启动tomcat,访问http://localhost:8080/html/index.html

image

html文件夹下的文件

image

访问:http://localhost:8080/html/index.html

image

如果想直接访问http://localhost:8080/index.html,可以修改conf/server.xml的配置,如图:在Host标签的内部,添加Context标签(配置完重启tomcat服务器)。

image

访问:http://localhost:8080/index.html

image

注:Tomcat中webapps目录下不能直接存放网页格式的文件,否则无法访问到该文件,必须有子目录才能访问该网页文件。

方法二:修改server.xml配置文件:

修改conf/server.xml文件,在Host标签中,添加<Context docBase="" path="" reloadable="" debug="" crosscontext="" />标签,其中

例子如下:

例子一:
image image

访问:http://localhost:8080/index.html

image
例子二:
image

访问:http://localhost:8080/test/index.html

image

如果path设置与webapps下的文件同名:

image

访问:http://localhost:8080/html/index.html

image

方法三:在conf/Catalina/localhost文件夹下添加xml文件:

文件的名字就是web项目的访问路径

image image

访问:http://localhost:8080/html3/index.html

image

二、tomcat部署web项目之动态配置:

方法一:web应用以war的方式部署:

1.打包war包的方式:

①进入cmd,输入jar,输出jar的使用信息。(如果提示:不是内部或者外部命令,应该是java环境没有配置好)
②进入要打包的文件目录,输入jar -cvf war包名字.war ./,输出打包的信息(默认war包就在该文件的目录下)。或者输入jar -cvf F:/test.war ./ (war包在f盘下)。
2.将war放到webapps下:

tomcat服务器启动时,会自动将webapps下的war包解压,创建一个与war包同名的文件,如果不想自动把war包解压,可以在server.xml文件中,将unpackWARs设为false。

①直接将war包放到webapps:启动tomcat,访问路径:http://localhost:8080/war包名字/index.html。此时可以按照上文静态配置的方法二,修改sever.xml配置,设置访问路径。

②将war包放到webapps下,修改war包名字为ROOT.war,删除原来的ROOT文件:启动tomcat,访问路径:http://localhost:8080/index.html

如图:

image

访问:http://localhost:8080/index.html

image

方法二:web应用使用Manager Web方式:

1.修改conf/tomcat-users.xml文件,添加管理角色。在
<tomcat-users></tomcat-users>里添加role和user。具体的例子可以访问localhost:8080,点击Manager App,关闭弹出框会进入添加管理角色的说明页面。
2.配置完后,访问http://localhost:8080,点击Manager App按钮,输入用户名和密码,进入在Tomcat Web Application Manager页面下,可以在Deploy里添加war包,配置web部署。
有两种方式:
①Deploy directory or WAR file located on server:
将war包(test.war)放到webapps下。
在WAR or Directory URL:添加访问路径(\test)。
点击Deploy按钮,启动服务,访问:http://localhost:8080/test/index.html

②WAR file to deploy:
点击选择文件按钮,选择war包(test.war),点击Deploy按钮,启动服务,访问:http://localhost:8080/test/index.html

如图:

修改tomcat-users.xml文件

image

访问:http://localhost:8080,点击按钮,在弹出框中点击取消,会显示修改tomcat-users.xml文件的示例,如下图:

image image

登录成功后,进入如下页面:

image

在下面进行war包的设置

image
上一篇 下一篇

猜你喜欢

热点阅读