Original address: http://www.blogjava.net/sealyu/archive/2010/01/08/308706.html
Procedure
- Prerequisites and assumptions
- Step One-prepare the Tomcat Manager application
- Step two-create a New Web App Using Maven
- Step three-define Your Tomcat Server in Maven Settings
- Step four-point Your Pom to Your Tomcat Server
- Step Five-build and Deploy the Web App
Prerequisites and assumptions
- Maven is already installed
- A Local instance of Tomcat is already installed and configured to run on port 8080
- Optional-eclipse is installed
Step One-prepare the Tomcat Manager application
In order to deploy a Web app for your Tomcat server, you'll need to ensure so you can access the Tomcat Manager Applica tion at:http://localhost:8080/manager/html. Typically, you just need to ensure that your <tomcat>/conf/tomcat-users.xml file has the following defined:
<?xmlversion=‘1.0‘encoding=‘utf-8‘?> |
<rolerolename="manager"/> |
<userusername="admin" password="admin"roles="admin,manager"/> |
In this case, we'll be logging in to the Tomcat Manager app using:
| Username |
Admin |
| Password |
Admin |
??? Back to Top
Step two-create a New Web App Using Maven
Next, we'll use a Maven archetype to generate a new Web application project.
Assuming that you'll primarily use eclipse as your IDE, your may wish to start the project within Eclipse. We ll start the project within Eclipse and then use MAVEN to fill the project in with the proper MAVEN web app structure.
- In Eclipse create a new general project. New > Project ... > General > Project
- Project name: "SW" (Name it what is wish, but remember to replace ' SW ' with your project name in all instances where that Appears in the This document is
The steps above just create a general project in your Eclipse workspace (e.g. a folder with a. Project Settings file Insid E of it).
Next, open a command prompt, CD into the ' SW ' project directory, and then execute the following Maven command Line):
-DgroupId=com.burlesontech.sw |
-DarchetypeArtifactId=maven-archetype-webapp |
You project'll now has the following structure:
In Eclipse, right-click on the project and select Refresh to see this stuff within Eclipse. (Note that the. project file would typically not appear within Eclipse, but it is there.)
??? Back to Top
Step three-define Your Tomcat Server in Maven Settings
Open your Maven settings.xml file (e.g. C: "Documents and Settings" Administrator ". M2" settings.xml) and add a server ' Myserv Er ' with the credentials-logging into the Tomcat Manager application:
<username>admin</username> |
<password>admin</password> |
??? Back to Top
Step four-point Your Pom to Your Tomcat Server
Open the Pom.xml file in the ' SW ' project and replace the <build> sections so, it looks like this:
<finalName>sw</finalName> |
<groupId>org.codehaus.mojo</groupId> |
<artifactId>tomcat-maven-plugin</artifactId> |
<server>myserver</server> |
Here, we had added the Tomcat plugin for Maven. Note that the <configuration> sections needs to the server defined in Settings.xml (' myserver '). The <finalName> and the <path> is used to tell the web context, the want to deploy to. In this case, we'll be able to access our application ATHTTP://LOCALHOST:8080/SW.
??? Back to Top
Step Five-build and Deploy the Web App
On a command prompt, you can now CD into the Sw/webapp directory where the project Pom exists. The Execute the following command:
If you get a BUILD successful message, you should then is able to access your Web application at http://localhost:8080/sw/ .
You should see "Hello world!" in your Web browser (from the index.jsp page). Now your ' re all set and ready to start building the next killer Web app!
If you try to deploy again with the same command, you'll likely get a FAIL message because the application already exist s at the path. For successive deployments, use the following command instead:
Next, want to enable log4j logging for your new application; Check out how to setup log4j in a Web app-fast.
How to create a Maven web app and deploy to Tomcat-fast