Below I will provide the steps to create a web-app using maven and get it running on tomcat, in just 5 minutes and without downloading and setting anything explicitly.
What you need is :
1. jdk 1.5 and above
2. maven 3
3. Eclipse or any IDE
We would be using maven archetype to create initial setup of our project.
1. Navigate to the folder where you want to create your app and run this command.
mvn archetype:generate -DgroupId=com.anirudh.myLearningPortal -DartifactId=myLearningPortal -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
2. Now go to the newly created project folder : cd myLearningPortal
3. Here you will see the complete directory structure and a POM.xml
4. To import this projecct to eclipse, run the following command :
5. Import this project in eclipse as an existing project.
6. Now run mvn clean install to make sure everything is fine and the project is setup correctly.
7. After build is successful. Lets add tomcat plugin and maven compiler plugin in POM.xml so that we dont need to setup tomcat or do any manual build and deploy.
<plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <username>admin</username> <password>admin</password> <server>myserver</server> <path>/myLearningPortal</path> </configuration> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins>
8.Finally run mvn clean install on the project folder.
9. If build is successful, run the below command:
mvn tomcat:run -Dmaven.tomcat.port=7080
10.When the server has started hit http://localhost:7080/myLearningPortal.
You will see “Hello World”, you can modify index.jsp to change the message.
So, now you have the running web-app, Now you can add any dependencies of spring,hibernate you wish to add in your application in POM.xml.
And compile,build and deploy your app in 2 commands.
1.Continous delivery, early feedback.
2.Any changes to view/jsp, no need to restart/compile ,it will reflect changes on page refresh.