Tomcat starts the specified project

Source: Internet
Author: User
Tags file url java web

See if Server.xml,conf/localhost/,web.xml is configured with other WebApp applications, but the actual address has been removed and the work directory is being emptied.




http://blog.163.com/mouse_lb/blog/static/6945620067863934935/




Http://zhidao.baidu.com/question/165259640.html



http://www.newsmth.net/pc/pccon.php?id=10003032&nid=402938


Methods for three deployment projects in Tomcat
The first method: in the Conf directory in Tomcat, add in the,<context path= "/hello" docbase= "d:eclipse3.2.2forwebtoolsworkspacehellowebroot" debug= "0" privileged= "true" >
</Context>
As for the context node properties, see the documentation in detail.

The second method: Copy the Web project file to the WebApps directory.

The third way: very flexible, in the Conf directory, the new Catalina (note case) \localhost directory, the directory to create a new XML file, the name can be arbitrarily taken, as long as the file name and the current document does not duplicate the line, the content of the XML file is:
<context path= "/hello" docbase= "d:eclipse3.2.2forwebtoolsworkspacehellowebroot" debug= "0" privileged= "true" >
</Context>

The 3rd method has the advantage that you can define aliases. The name of the project running on the server side is path, and the externally accessed URL uses the XML file name. This method is very convenient to hide the name of the project, some project names are fixed can not be replaced, but the external access and want to change the path, very effective.

2nd, 3 also has the advantage, may define some personality configuration, like the data source configuration and so on.

There is also an article in detail

Here are a few of the three ways that Tomcat deployment publishes JSP applications
1, directly into the WebApps directory
Tomcat's WebApps directory is the tomcat default application directory that loads all applications under this directory when the server is started. You can also package a JSP program into a war package and place it in the directory, and the server will automatically unlock the war package and generate a folder with the same name in this directory. A war package is an attribute-formatted jar package that compresses all the contents of a Web application. How to package, you can use a number of development tools IDE environment, such as Eclipse, NetBeans, Ant, JBuilder, and so on. can also use cmd command: JAR-CVF applicationname.war package.*;
You can even package in program execution:
try{
String strjavahome = System.getproperty ("Java.home");
Strjavahome = strjavahome.substring (0,strjavahome.lastindexof (\)) + "\\bin\\";
Runtime.getruntime (). EXEC ("cmd/c start" +strjavahome+ "Jar CVF hello.war c:\\tomcat5.0\\webapps\\root\\*");
}
catch (Exception e) {System.out.println (e);}

WebApps This default application directory can also be changed. Open the Server.xml file under Tomcat's Conf directory and find the following:

2, in the server.xml specified
In Tomcat's configuration file, a Web application is a specific context that can be deployed by deploying a JSP application in a new context in Server.xml. Open the Server.xml file and build a context within the host tag, as follows.
<context path= "/myapp" reloadable= "true" docbase= "D:\myapp" workdir= "D:\myapp\work"/>
Where path is the virtual path, Docbase is the physical path to the JSP application, Workdir is the working directory of the application, and the runtime is the file generated for this application.

3. Create a context file
In both of these ways, when a Web application is loaded by the server, it generates an XML file in the Tomcat's Conf\catalina\localhost directory, which reads as follows:
<context path= "/admin" docbase= "${catalina.home}/server/webapps/admin" debug= "0" privileged= "true" ></ Context>
As you can see, the file describes the context information for an application, and its content is consistent with the format of the Server.xml context information, which is the name of the virtual directory. You can create such an XML file directly under Tomcat's Conf\catalina\localhost directory. Examples are as follows:
Note: Deleting a Web application also deletes the corresponding context in the WebApps under the Server.xml, and the Tomcat's Conf
Delete the corresponding XML file in the \catalina\localhost directory. Otherwise tomcat will still be configured to load the shore ...




http://blog.163.com/mouse_lb/blog/static/6945620067863934935/


set up the servlet to start with WebApp

2006-08-08 18:39:34| Category: java| font size subscription reason: mainly convenient to do some initialization work in advance of WebApp startup

1. Configure Web.xml
Add the following:
<servlet>
<servlet-name>ServletInit</servlet-name>
<servlet-class>xx.xx.xx.xx.ServletInit</servlet-class>
<!--
Defining initialization parameters
Use string debug = Getservletconfig (). Getinitparameter ("Debug") in Servletinit;
-->
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<!--
Key: Set this servlet to start with WebApp
2 represents the millisecond, that is, WebApp starts the servlet after 2 milliseconds
-->
<load-on-startup>2</load-on-startup>
</servlet>

2.
public class Servletinit extends HttpServlet {
public void init (ServletConfig config) throws servletexception {
Use Config.getinitparameter (param-name) to get initialization parameters
Class
}

public void Destroy () {
Do some work when WebApp quit
}
}

There is also a problem initializing the read configuration file, and the Init function calls methods of other classes, when the program executes to other classes
, the configuration file in the current directory was not found, and it was later discovered that the servlet was started with Tomcat and the current path has become Tomcat
The bin of the installation directory, so can not find the configuration file, and then after the person pointing to the init function to add:
ServletContext sc = Config.getservletcontext ();
Get current absolute path
String RootPath = Sc.getrealpath ("/");
As a result, RootPath is the path to Tomcat deployment of this webapp, assuming that the Tomcat installation directory is $tomcat and its directory results are as follows:
$TOMCAT
bin/
common/
conf/
Other catalogs/
webapps/
myownapp/
conf/
web-inf/
Other
Then RootPath is "$TOMCAT/webapps/myownapp/" so that the Conf configuration file in this directory can be found wherever the app is deployed.

There is also a similar function for JSPs: String Root_path = Application.getrealpath ("/");



http://blog.csdn.net/yangxueyong/article/details/6130065



http://blog.csdn.net/yangxueyong/article/details/6130065



Tomcat Deployment Web application Methods Summary Category: Java Web 2011-01-11 23:12 634 people read Comments (0) Favorites Report Summary of Tomcat Deployment Web application methods

There are two ways to deploy Java Web applications in Tomcat: Static deployment and dynamic deployment.

In the following, $catalina_home refers to the Tomcat root directory.

first, static deployment

Static deployment means that we deploy our programs before the server is started, and our web applications are accessible only after the server is started.

All of the following 3 ways can be deployed: (Take the Petweb project as an example, the Petweb directory is assumed to be f:/petweb)

1. automatic deployment with Tomcat

Copy the Petweb directory to $catalina_home/webapps, then start the server, and the application will be loaded automatically when Tomcat starts.

The visit address is as follows: http://localhost:8080/PetWeb/

This approach is simpler, but the Web application must be in the WebApps directory. Tomcat's WebApps directory is the tomcat default application directory that loads all applications under this directory when the server is started.

2. Modify Server.xml File Deployment

This way you can not necessarily copy Petweb directory to WebApps, directly in f:/deployment. The following method, change the $catalina_home/conf/server.xml file,

Find the following:

XML code: <context Path = "/pet" reloadable = "false" DocBase = "F:/petweb" Workdir = "d:/mywebapps/emp"/&G t;

Path: is the root address at the time of the visit, which indicates the path of the access; In the example above, access to the application address is as follows: http://localhost:8080/Pet/

Reloadable: Indicates that the class package can be loaded automatically at run time under the classes and Lib folders. where reloadable= "false" means that the server does not automatically load when the content in the application is changed, and this property is typically set to true during the development phase, easy to develop, and should be set to false during the publishing phase to increase the access speed of the application.

Docbase: Represents the path of the application, paying attention to the direction "/" of the slash. Docbase can use absolute paths or relative paths, relative paths relative to WebApps.

Workdir: Represents the placement address of a cached file

3. Add custom Web Deployment files (recommended, do not need to restart Tomcat)

This approach is similar to Method 2, but instead of adding a context tag to the Server.xml file, add an XML file to the $catalina_home/conf/catalina/localhost. such as Pet.xml. Under the Tomcat installation directory Conf/catalina/localhost, there are Tomcat's own three applications, copy one of the XML files, and then modify the docbase point to your own application, and rename the file name, Refer to the parameters of the <Context> tag in Method 2, or you can create a new XML file yourself. (Note that this file name is the Path property value in the context, regardless of how the path attribute value in the file is set to be invalid), copy the following and modify the appropriate path.

XML code: <context Path = "/pet" docBase = "f:/petweb" debug = "0" privileged = "true" reloadable = "FAL" Se " > </Context>

The visit address is as follows: http://localhost:8080/Pet/

Note: Web applications are deployed as. War Files

You can package a JSP program into a war package and place it in the directory, and the server will automatically unlock the war package and generate a folder with the same name in this directory. A war package is an attribute-formatted jar package that compresses all the contents of a Web application.

We have just deployed the Petweb folder to the server, and we know that the content of the Web application can be typed as a. War package and then deployed on the server. For packaging please refer to the following steps:
1, open the command prompt (CMD)
2. Set JDK environment variables
3. After entering the f:/petweb of the project folder at the command prompt, type the following command:jar CVF Pet.war * *. (Note that there's a "." At last.) )。 This should have Pet.war files under the F:/petweb. (You can also package to the specified place, the command is as follows:jar CVF D:/pet.war * *.

Deploying the Pet.war file is very simple, change the Docbase = "F:/petweb" in the xml file to Docbase = "F:/pet.war" or simply copy it to the WebApps directory. You can then restart the server to deploy Pet.war as a Web application.

If you're careful, you'll find that the server Pet.war the file and creates a pet folder underneath the WebApps, and then copies the contents of Pet.war to the inside. We can cancel the automatic decompression in the following way, set the Unpackwar property in the XML configuration file to "false".

second, dynamic deployment

Dynamic deployment means that a Web application can be deployed after the server is started without restarting the server. Dynamic deployment to use the Manager.war file provided by the server, if you do not have the file under $catalina_home/webapps/, you must download tomcat, otherwise you will not be able to complete the following functions. To use this manager you must first edit the $catalina_home/conf/tomcat-users.xml file as follows: (For more on this file, refer to the Java Web application's security Model II) <tomcat-users >
<role rolename= "Tomcat"/>
<role rolename= "Role1"/>
<role rolename= "Manager"/>
<user username= "Coresun" password= "Coresun" roles= "manager"/>
<user username= "Tomcat" password= "Tomcat" roles= "Tomcat"/>
<user username= "Both" password= "Tomcat" roles= "Tomcat,role1"/>
<user username= "Role1" password= "Tomcat" roles= "Role1"/>
</tomcat-users>

Then type the following address in the browser: http://localhost:8080/, you should see a Garfield cat. Click on the Tomcat Manager link on the left, prompt for username and password, this article is Coresun, then you can see the following page:

(1) Context Path (option): Enter/pet


(2) XML configration A. xml file in the file URL, for example, we create a pet.xml file under f:/, which reads as follows:<context reloadable = "false" / > . DocBase don't have to write, because you want to fill in the next text box. Or more simply, this text box doesn't fill anything.


(3) WAR or Directory URL: type F:/petwet or F:/pet.war in, and then click on the Deploy button to see if you have seen the Web application, the name is your context Path (option): Name.


(4) If you are deploying a. War file there is a simpler way, there is also a select War file upload click to browse to select the. war files, and then click Deploy.

let Tomcat run only the Web application specified in Conf/server.xml

There are 2 ways to do this:

Achieve one:

1 The Web application to be deployed is placed outside the WebApps path and specified in the Docbase in the corresponding context of server.xml.

2 Delete all the folders in the WebApps and conf/catalina/localhost all the XML files.
Note: WebApps is the value of the AppBase property of the Host element in Server.xml.

Realize two:

Modify the properties of the Host element in Server.xml, add or modify: Deployxml = "false" Deployonstartup = "false" autodeploy= "false"

Meaning:
Deployxml = "false": do not deploy XML under conf/catalina/localhost corresponding Web application

Deployonstartup = "false": all Web applications under WebApps are not deployed when Tomcat is started

Autodeploy = "false": avoid tomcat to deploy Web apps under WebApps again when scanning for changes.

Note:

A file that cannot be directly stored in a Web page in the WebApps directory of Tomcat cannot access the file, and a subdirectory is required to access the Web page file.
For example: We put index.html directly in the WebApps directory, http://localhost:8080/index.html is inaccessible to index.html through the browser. And you have to webapps/petweb/index.html to be able to access the Index.html page through http://localhost:8080/petweb/index.html.

" Comprehensive reference to the free passage of the article"

1.http://lukas06.blog.sohu.com/112367177.html TOMCAT Deployment Web Application

Three ways to 2.http://blog.csdn.net/jierui001/archive/2009/05/11/4168872.aspx Tomcat deployment Web applications

3.http://ericxu131.javaeye.com/blog/175831 deployment of Java Web Applications in tomcat (turn)

4.http://secyaher.blog.163.com/blog/static/3895577200781495722337/the project into a war file and at Tomcat


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.