1. Create a new Maven project in Eclipse with war as the packaging type
2. Edit the pom.xml as follow
<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>spring-mvc-trial</groupId> <artifactId>spring-mvc-trial</artifactId> <packaging>war</packaging> <version>1.0</version> <name>Spring MVC Trial</name> <description>Spring MVC Trial</description> <!-- Build Configuration --> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.1</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> </project>
3. Create /src/main/webapp/index.jsp
<head><title>Example :: Spring Application</title></head> <body> <h1>Example - Spring Application</h1> <p>This is my test.</p> </body>
4. Create /src/main/webapp/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
6. A .war file is built at /target and copy it to the Tomcat webapp folder
7. Verify the deployment in browser
Done =)
Can you explain how you installed the maven plugin on eclipse ?
I’m trying to install it but I do not understand how to do it …
LikeLike
This should help~ =P
Eclipse and Maven – m2eclipse
LikeLike
I agree with the comment above, you should include that part in this tutorial!
LikeLike
O, sorry, i found that i created a wrong link on the above comments. i have fixed the link.
The linked url is another blog post which i wrote about installing the m2eclipse on eclipse.
Eclipse and Maven – m2eclipse
does it help?
LikeLike
Thank you for this help. I actually already had Maven (m2eclipse) installed. I am lost on how to use it from within Eclipse. Or, if from the command line, which commands to run.
LikeLike
a maven project contains different life cycle phases. for example, if you want to run test cases, you can run the
mvn test
if you want to build the project
mvn install
the install phase will include the package and test phases etc.
for more information about the maven command, you can take a look @
Maven Getting Started Guide
If you are new to Maven, the following book is really a nice start for you
Sonatype – Maven: The Complete Reference
Hope it can help you to start maven. it is really a great tool for java development. =)
LikeLike
I’m still lost on #5. Can you detail it?
LikeLike
Do you mean Run Maven Install? this is a maven command which start the project build process.
actually what problem did you have? could you install the m2eclipse plugin?
If you are using the latest version of eclipse, the installation maybe a bit difference in Eclipse and Maven – m2eclipse.
LikeLike
I actually meant where you find that command in Eclipse! Where do you go in Eclipse to get those options?
LikeLike
The command line is just “mvn install” I realize.
LikeLike
haha~ seems i am too far away from your question. anyway, good to know that you get the answer. =D
LikeLike
I am sorry for this newbie question. at step 5 and 6 it says /target folder… where is /target folder. Please help
LikeLike
The /target folder is created by maven automatically after you run the mvn install command.
LikeLike
Thank you for your reply, actually I found the war file also, I done all the steps as you told but when I deploy it to tomcat that is I copy the war file to webapp of tomcat and run the tomcat, when hitting the same URL it says HTTP Status 404. please help me
LikeLike
can you show me the path where you put the war file in the tomcat?
LikeLike
The path where I put the war file in the tomcat
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps
LikeLike
Could you find the spring-mvc-trial-1.0 folder inside the webapps folder?
LikeLike
yes I do
LikeLike
That’s weird.
how about the following 2 urls?
1. http://localhost:8080/spring-mvc-trial-1.0/hello.jsp
2. http://localhost:8080/spring-mvc-trial-1.0/index.jsp
and is your tomcat running on port 8080? you can access http://localhost:8080/ which shows the default tomcat page, rite?
LikeLike