[Translation] Tomcat 6.0 release and deployment

Benpian reference Tomcat official document: " First Webapp " translation, and development of their own experience introduce the relevant content on tomcat deployment and release.

1 Directory Structure

  Tomcat in all the applications are placed in the CATALINA_HOME / webapps, which corresponds to CATALINA_HOME is the root directory of your tomcat.

  Since the version specification after Servlet2.2 provisions tomcat directory structure in the application must meet a fixed format, it is easy to regulate consistency.

  Placed in the webapps file is usually in two formats: a good project file compression, such as war package! One is the normal folder.

  If this package is a war project file, tomcat will automatically unzip it after the start to the current directory, the file becomes accessible folder.

  The directory structure comprising:

/apps
    |------/WEB-INF
            |------/classes 编译的字节码文件
            |------/lib 需要的类库,jar包
            ------web.xml
    |------/META-INF
            ------context.xml
    ------普通前端页面,jsp等等

  The basic contents of the same details as described above.

  Which focuses  web.xml  file, which is also called the deployment descriptor for the web application configuration information.

  have to be aware of is:

  Note that the arrangement order of the same items, will be executed or loaded Tomcat configuration order.

  Caveats such as filters, as well as some of the pages to load.

 

  In which the meaning, Baidu also get to know about

<web-app>   
<display-name></display-name>定义了WEB应用的名字   
<description></description> 声明WEB应用的描述信息   
 
<context-param></context-param> context-param元素声明应用范围内的初始化参数。   
<filter></filter> 过滤器元素将一个名字与一个实现<a href="http://www.cnblogs.com/bukudekong/archive/2011/12/26/2302183.html">javax.servlet.Filter</a>接口的类相关联。   
<filter-mapping></filter-mapping> 一旦命名了一个过滤器,就要利用filter-mapping元素把它与一个或多个servlet或JSP页面相关联。   
<listener></listener>servlet API的版本2.3增加了对事件监听程序的支持,事件监听程序在建立、修改和删除会话或servlet环境时得到通知。   
                     Listener元素指出事件监听程序类。   
<servlet></servlet> 在向servlet或JSP页面制定初始化参数或定制URL时,必须首先命名servlet或JSP页面。Servlet元素就是用来完成此项任务的。   
<servlet-mapping></servlet-mapping> 服务器一般为servlet提供一个缺省的URL:http://host/webAppPrefix/servlet/ServletName。   
            <span style="color: #008000;">  但是,常常会更改这个URL,以便servlet可以访问初始化参数或更容易地处理相对URL。</span>在更改缺省URL时,使用servlet-mapping元素。   
 
<session-config></session-config> 如果某个会话在一定时间内未被访问,服务器可以抛弃它以节省内存。   
          可通过使用HttpSession的setMaxInactiveInterval方法明确设置单个会话对象的超时值,或者可利用session-config元素制定缺省超时值。   
 
<mime-mapping></mime-mapping>如果Web应用具有想到特殊的文件,希望能保证给他们分配特定的MIME类型,则mime-mapping元素提供这种保证。   
<welcome-file-list></welcome-file-list> 指示服务器在收到引用一个目录名而不是文件名的URL时,使用哪个文件。    
<error-page></error-page> 在返回特定HTTP状态代码时,或者特定类型的异常被抛出时,能够制定将要显示的页面。   
<taglib></taglib> 对标记库描述符文件(Tag Libraryu Descriptor file)指定别名。此功能使你能够更改TLD文件的位置,   
                  而不用编辑使用这些文件的JSP页面。   
<resource-env-ref></resource-env-ref>声明与资源相关的一个管理对象。   
<resource-ref></resource-ref> 声明一个资源工厂使用的外部资源。   
<security-constraint></security-constraint> 制定应该保护的URL。它与login-config元素联合使用   
<login-config></login-config> 指定服务器应该怎样给试图访问受保护页面的用户授权。它与sercurity-constraint元素联合使用。   
<security-role></security-role>给出安全角色的一个列表,这些角色将出现在servlet元素内的security-role-ref元素   
                   的role-name子元素中。分别地声明角色可使高级IDE处理安全信息更为容易。   
<env-entry></env-entry>声明Web应用的环境项。   
<ejb-ref></ejb-ref>声明一个EJB的主目录的引用。   
< ejb-local-ref></ ejb-local-ref>声明一个EJB的本地主目录的应用。   
</web-app>
View Code

  More common is the listener, filters, servlet, session management, initialization parameters, and so on.

 

  classes  folder placement is to compile a .class file, such as a package you define: com.test.hello.java after the start tomcat release, will be found in the classes file in the folder application response com /test/hello.class file. Similar servlet, bean, plain java class will be compiled into here.

  lib  folder is placed under the jar package project applications. Such as the use of SSH, the project cited jar package, the final will be placed here. This folder jar file is not compiled into classes folder. For more information refer to the tomcat class loading mechanism.

 

  In addition, this folder a jar that is part of the application you use. tomcat root directory and a lib folder, which is stored inside the basic servlet and jsp required jar package.

  If you have some experience in the development of friends will find themselves sometimes inside the IDE development, baffling reported some errors. However, these errors do not affect the final release. This is because in the development, IDE did not find the corresponding jar package, these packages are stored in a jar in the tomcat. When the application is released, automatically find the folder, it will not be the error.

  Solution, that is, when redevelopment, the tomcat lib folder added to the build environment IDE.

 

  context.xml  often configure some parameters change language runtime, so that the document can be scanned periodically tomcat, the corresponding operation.

  Why should this document?

  Because other profile information such as tomcat server.xml are read at startup, run-time can not be changed, so some dynamic information set here can be dynamically loaded during run. When the configuration data is commonly used source JNDI, which will explain in detail the contents of the configuration file later explain.

2 Deployment

  What is deployment?

  In fact, the complete development of the code in tomcat, if you are using a notepad to develop, copy directly to the webapps.

  If you are using IDE development, we need to make tomcat integrated into the IDE, and the path configuration mapping code.

  Directly in the IDE, right-tomcat ---> Add and Remove ...

 

  If you can not find items to add to the left to the right, and an error. Check the version of servelt. Usually due to tomcat servlet and lead to inconsistent versions, the reference version of the relation:

  For example, tomcat6 only supports servlet versions prior to 2.5, and later versions of JDK 1.5. ,

3 release

  Release is to use the code to compile and organize so that users can directly access.

  Like the production of a car, tomcat responsible for the individual parts to be assembled (the code is compiled Organization), the last run directly to a car (application accessible) placed in front of the user.

  Published methods:

  1 run directly in the tomcat: run startup.bat or startup.sh file. Reference run: Tomcat start

  2 in the IDE Start:

  In the server view, right-tomcat select start or click the upper right corner of the DEBUG or START icon

4 Test

  After the implementation of release, you can log browser, enter: HTTP: // localhost: 8080 / [the webapp name] to access the application.

  Where 8080 is the port number, or by server.xml the IDE interface to modify the configuration.

  Document also gives the thread pool configuration and SSL

 

  Options can also double-click tomcat server view in the IDE, pop-up configuration interface, modify the port number, remember to save.

  localhost as the host name: You can also use the local address 127.0.0.1, the local IP address or [can with ipconfig / all inquiries]

Reproduced in: https: //my.oschina.net/u/204616/blog/545093

Guess you like

Origin blog.csdn.net/weixin_33939843/article/details/91990044