Saturday, June 20, 2015

Create a war file using eclipse maven plugin

In this post I will explain how to set up eclipse to create war file from dynamic web project. Later it can be use to deploy web application on tomcat.

Prerequisites 
  1. You should have install java in your PC and set path variable correctly (JAVA_HOME, JRE_HOME)
  2. You should have Apache Tomcat in your machine.
  3. You should have install Eclips Java EE LUNA IDE in your PC.

Step 1 First create Dynamic web project 

As a first step we needs to have web project to create war file from it. So to create dynemic web project Go to New->Other and select dynamic web project then provide project name and select run time environment. In this post I'm using project name as SampleMavenProject and my run time environment as tomcat 7.

Then add new index.jsp file to webcontent directory in your project structure and add following content in to that.


<html>
    <head>
        <title>Index File Maven Project</title>
    </head>
    <body>
        <b>Maven test project running</b>
    </body>
</html>

Then we have to convert the Dynamic Web Project in to Maven Project to do that right click on project and go to Configure->Convert to Maven Project. (Figure 1)

Figure 1: Convert to Maven project

Then next interface you can provide details regarding the war file that you are going to create such as war file name and version etc and then click Finish. (Figure 2)

Figure 2: Provide details about project

After you click Finish you can see new pom.xml file is created on your project and in pom.xml you can see automatically added maven plugin details in to plugin section. (Figure 3)

Figure 3: New pom.xml created in project structure 

Then lets create war file from the project. Click right click on Run As->Maven Build and enter clean install in Goals and click run. (Figure 4)

Figure 4: Add clean install in Goals section

Then you can see similar out put in console in that you can see Build success notification and the war file generated location.(Figure 5)

Figure 5: Console out put

We have successfully created war file from our project. If you need to deploy it to Apache Tomcat then go to the war file generated location and copy that war and past it in webapps 
Apache Tomcat directory.
Then start the Apache Tomcat server and you can see your project folder will extracted in webapps folder. Then you can access you project on relevant project link. 


No comments:

Post a Comment