Using eclipse with maven plugin, how should I setup my build so it deploys to tomcat?
Using eclipse with maven plugin, how should I setup my build so it deploys to tomcat?
I'm not sure if I have to do this in 1 or 2 steps, but I want to compile my spring mvc (3) application and deploy to my local tomcat.
Right now I just mapped the RunAs -> Maven build to a 'compile' goal type.
I'm very new to do this so not sure how to setup build and deploy.
My pom.xml is:
<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.example</groupId>
<artifactId>springmvc2</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springmvc2 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mod4j.org.apache.commons</groupId>
<artifactId>logging</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
<build>
<finalName>springmvc2</finalName>
<filters>
</filters>
<开发者_运维知识库;plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Inside Eclipse
Assuming you have the WTP (Web Tools Project) installed (which is part of the Eclipse IDE for Java EE developers distro) and you have the "Maven Integration for WTP" installed (which is an optional module of m2eclipse, you have to intall it explicitly), then your spring project should be recognized as a dynamic web project and runnable on a Server. In that case, just right-click on your project, go to Run As > Run on Server, select Manually define a new server and use the wizard to add your local Tomcat.
Outside Eclipse
You can simply execute:
mvn tomcat:run
This will run the current project as a dynamic web application using an embedded Tomcat server.
If what you want is really to deploy to your local Tomcat, then have a look at the tomcat:deploy
goal.
Of course, you can always run these goals from Eclipse but I'd recommend to use the IDE support here (i.e. the WTP). This will be easier if you want to run your Tomcat in debug mode, etc.
精彩评论