How to deploy tomcat

1. Static deployment

1. Copy the web project files directly to the webapps directory.
     Tomcat's Webapps directory is the default application directory of Tomcat. When the server starts, all applications in this directory will be loaded. So you can package the JSP program into a  war package and put it in the directory, the server will automatically unpack the war package and generate a folder with the same name in this directory. A war package is a jar package with a characteristic format , which is obtained by compressing all the contents of a web program. Specifically how to package, you can use the IDE environment of many development tools, such as Eclipse. You can also use the  cmd command: jar -cvf mywar.war myweb       webapps This default application directory can also be changed. Open the server.xml file in Tomcat's conf directory and find the following:

<Host name="localhost" appBase="webapps"

       unpackWARs="true" autoDeploy="true"

       xmlValidation="false" xmlNamespaceAware="false">

Just modify the appBase. 
2. Specify in server.xml  
    In Tomcat's configuration file, a Web application is a specific Context, and a JSP application can be deployed in a new Context in server.xml . Open the server.xml file and build a Context in the Host tag , the content is as follows.

In the conf directory in tomcat , in server.xml, add in the <host/> node: <Context  path = "/hello"  docBase = "D:\ workspace\hello\WebRoot"  debug = "0"  privileged = "true">  </Context> 

or

<Context path="/myapp" reloadable="true" docBase="D:\myapp" workDir="D:\myapp\work"/>

or

<Context path="/sms4" docBase="D:\workspace\sms4\WebRoot"/>


illustrate:

path is a virtual path;

docBase is the physical path of the application;

workDir is the working directory of this application, which stores the files related to this application generated at runtime;

 

debug is to set the debug level, 0 means to provide the least information, 9 means to provide the most information

When privileged is set to true, Tomcat's web application is allowed to use the servlet in the container

If reloadable is true, tomcat will automatically detect changes in the /WEB-INF/lib and /WEB-INF/classes directories of the application, automatically load new applications, and change applications without restarting tomcat. Implement hot deployment

antiResourceLockingantiJARLocking  热部署是需要配置的参数,默认false避免更新了某个webapp,有时候Tomcat并不能把旧的webapp完全删除,通常会留下WEB-INF/lib下的某个jar包,必须关闭Tomcat才能删除,这就导致自动部署失败。设置为true,Tomcat在运行对应的webapp时,会把相应的源文件和jar文件复制到一个临时目录里。
3、创建一个Context文件 
  conf目录中,新建 Catalina\localhost目录,在该目录中新建一个xml文件,名字不可以随意取,要和path后的那个名字一致,按照下边这个path的配置,xml的名字应该就应该是hello(hello.xml),该xml文件的内容为:

<Context path="/hello" docBase="E:\workspace\hello\WebRoot" debug="0" privileged="true"></Context>

 

tomcat自带例子如下:

<Context docBase="${catalina.home}/server/webapps/host-manager"

         privileged="true" antiResourceLocking="false" antiJARLocking="false">

</Context>

这个例子是tomcat自带的,编辑的内容实际上和第二种方式是一样的,其中这xml文件名字就是访问路径,这样可以隐藏应用的真实名字。

4、注意:

    删除一个Web应用同时也要删除webapps下相应的文件夹和server.xml中相应的Context,还要将Tomcat的conf\catalina\localhost目录下相应的xml文件删除,否则Tomcat仍会去配置并加载。。。

二 动态部署

     登陆tomcat管理控制台:http://localhost:8080/,输入用户名和密码后便可管理应用并动态发布。

     在Context Path(option):中输入/yourwebname ,这代表你的应用的访问地址。

     XML Configration file URL中要指定一个xml文件,比如我们在F:\下建立一个hmcx.xml文件,内容如下: <Context reloadable="false" />其中docBase不用写了,因为在下一个文本框中填入。或者更简单点,这个文本框什么都不填,在WAR or Directory URL:中键入F:\hmcx即可,然后点击Deploy按钮,上面就可以看到了web应用程序,名字就Context Path(option):中的名字。


    如果部署.war文件还有更加简单的方式,下面还有个Select WAR file uploae点击浏览选择.war文件,然后点击Deploy也可以。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324696682&siteId=291194637