Deploying project, created with Eclipse and Maven, to Tomcat
I'm using Eclipse 3.5, Maven 2, m2eclipse and Tomcat 6. So i create Maven project for archetype webapp. This is pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.itransition</groupId>
<artifactId>hello</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>hello Maven Webapp</name>
<url>http://maven.apache.org</url>
<!-- tools.jar dependency -->
<profiles>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
&开发者_开发技巧lt;name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.1.8.1</version>
</dependency>
</dependencies>
<build>
<finalName>hello</finalName>
</build>
</project>
So then i want to deploy my web application to Tomcat. What I need to do? Maven install don't help. But if I create war by Maven install, i can import it to eclipse and deploy it to Tomcat by "Add and remove..." in server popup.
This problem can be resolved by using the Tomcat plugin for Maven. Its homepage has got extensive documentation concerning the configuration of the plugin and deployment of war files.
It can be done in 2 ways.
Refer below URL
http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
Create maven Project with eclipse and locate the project folder from command prompt (or) Terminal
mvn eclipse:eclipse -Dwtpversion=2.0 [ in project folder ]
Refersh Eclipse project.
Now you can Add and Remove Deployment.
Found out that the tomcat manager url (i am using Tomcat 6.0) is http://localhost:8080/manager/html
, while the default used by the mvn tomcat plugin stops at manager in the URL. Add the url specified to your pom.xml as a configuration parameter - (see this url for more details http://mojo.codehaus.org/tomcat-maven-plugin/configuration.html) and voilà it works...
With Tomcat7, I found I needed to set up the URL as http://localhost:8080/manager/html
and use a username with a manager-gui role. However, using a username with the manager-script role, with URL http://localhost:8080/manager/text
also works and is more appropriate. The manager-script role is the designed way to go for ant/maven scripts.
So then i want to deploy my web application to Tomcat. What I need to do? Maven install don't help. But if I create war by Maven install, i can import it to eclipse and deploy it to Tomcat by "Add and remove..." in server popup.
Since you are using m2eclipse, my recommendation would be to deploy your application using the WTP. Assuming you have the Maven integration for WTP feature installed (from m2eclipse extras) and Tomcat configured as Server, just right-click on your project and select Run > Run on Server...
Another option would be to run your application on Jetty (yes, I know that this is not what you're asking for but this is very valid option if you don't want to use the WTP). Add the following snippet to your pom:
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
</plugin>
</plugins>
</build>
</project>
And simply run mvn jetty:run
to start an embedded Jetty server and deploy your application on it.
The same can be achieved for Tomcat using the Tomcat Maven Plugin but unless you want to deploy to a remote Tomcat (see the Usage page), I don't see any advantage over the Maven Jetty Plugin.
During development, I would use the first option (deploy with the WTP).
If you want that your war
file created by maven
, should be deploy on tomcat server directly then this tomcat deployment configuration can help you.
精彩评论