1: The Environment
Eclipse Indigo,
JDK1.6,
Maven 3.2.1,
tomcat7.0.42 2: Install eclipse maven plugin M2eclipse
The first way: Download m2eclipse from the Internet, there are a lot of places to download. It is then placed under the plugins of the Eclipse installation directory.
The second method: Open Eclipse->help->install new software. Enter after work with: Http://download.eclipse.org/technology/m2e/releases. As shown in figure:
3: Download maven and Tomcat
The Apache website downloads maven:http://maven.apache.org/download.cgi. After the download is complete decompression can be.
The Apache website downloads tomcat:http://tomcat.apache.org/. 4:eclipse config maven
window-"prefrences-" maven-"user setting. As shown in figure
window-"prefrences-" maven-"installations. As shown in figure
5: Configure Tomcat and Maven
Enter Tomcat_home/conf/tomcat_users.xml: Modified as follows:
<role rolename= "Admin-gui"/> <role rolename= "admin-script"/> <role "rolename="
/ >
<role rolename= "Manager-script"/> <role rolename= "manager-jmx"/> <role "rolename=
" Manager-status "/>
<user username=" admin "password=" admin "roles=" manager-gui,manager-script,manager-jmx , Manager-status,admin-script,admin-gui "/>
Enter Maven_home/conf/settings.xml: Modified as follows:
<server>
<id>tomcat</id>
<username>admin</username>
<password> Admin</password>
</server>
6:eclipse Create a MAVEN Web project
This simple, new-"other-" Maven project-"next." Notice here GroupID Select Org.apache.maven.archetypes, Artifactid select Maven-archetype-webapp, then Next, Enter our own GroupID (com.test), Artifactid (Transition), and then Finish,ok. As shown in the figure:
7: Modify the 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.test</groupId> <artifactid>transition</ artifactid> <packaging>war</packaging> <version>0.0.1</version> <name>transition
Maven webapp</name> <url>http://maven.apache.org</url> <repositories> <repository> <id>maven_remote_1</id> <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url> </r epository> </repositories> <dependencies> <dependency> <groupid>junit</groupid > <artifactId>junit</artifactId> <version>3.8.1</version> <SCOPE>TEST&L T;/scope> </dependency> </dependencies&Gt <build> <finalName>transition</finalName> <plugins> <plugin> <groupid& Gt;org.codehaus.mojo</groupid> <artifactId>tomcat-maven-plugin</artifactId> <configuratio n> <warFile>target/transition.war</warFile> <server>tomcat</server> <ur L>http://localhost:8080/manager/text</url> <path>/transition</path> </configuration>
;
</plugin> </plugins> </build> </project>
8: Run MAVEN project
Start Tomcat first into the Tomcat directory, then right-click Project Run as-run Configrations:
Goals Entry: Package Tomcat:redeploy
MAVEN runtime choose our own maven. As shown in figure:
Then click Run, and the console appears as follows:
[info] processing War project [INFO] Copying WebApp resources [E:\transition\src\main\webapp] [INFO] Webapp assembled in [3 msecs] [info] building War:e:\transition\target\transition.war [info] Web-inf\web.xml already adde D, skipping [info] [INFO] <<< Tomcat-maven-plugin:1.1:redeploy (DEFAULT-CLI) @ transition <<< [INFO] [ INFO]---tomcat-maven-plugin:1.1:redeploy (default-cli) @ transition---[INFO] deploying war to http://localhost:8080/t ransition [INFO] ok-undeployed application at Context path/transition [INFO] ok-deployed application in context Pat h/transition [INFO]------------------------------------------------------------------------[INFO] Build SUCCESS [ INFO]------------------------------------------------------------------------[INFO] Total time:2.412 s [INFO] Finished at:2014-03-13t11:43:42+08:00 [INFO] Final memory:6m/15m [INFO]-------------------------------------------- ----------------------------
A lot of console output is omitted here, and a build SUCCESS indicates a successful deployment, and the browser input: http://localhost:8080/transition/. Show Hello World.
Note: After this success, the project will be made into a war package and deployed to Tomcat with no restart Tomcat required for each build. The fatal disadvantage is that you cannot debug. If you need to debug and start Tomcat in Eclipse. You will find that the right key item does not have run as server, and there are two ways to fix it:
First: You need to turn the project into Dynamic Web module. Right-key Item-"properties-" project facets, then select Dynamic Web Module on the right. The run as server will then appear.
The second: The right key item, Run/debug as configrations as the figure on the 8th step. But goals "Tomcat:run" in the sky. Then run is OK, note that there is no need to start Tomcat in advance.