Home | WebServices | Maven | SOA | REST | Agile & SCRUM | Java & JEE
Homepage

Setup web application using spring Struts 2 and Maven with Eclipse 3.3


Incase you have any difficulty in configuration please post in our Forum.

We will use MySQL as the database. Hence please install MySQL 5.x on your machine.
Choose any empty folder where we can set up the web project. I have chosen the folder E:\theacodefactory\code\airelinesweb. [It should have been airlinesweb..anyway it does not matter :)]. Open command prompt and go to the chosen folder. Ensure Maven 2.0.x set up is proper by typing mvn -v and verifying the output as in the screenshot below.
mvnverify (6K)
We will create a project airlines using an archetype from AppFuse. Enter the below command and execute it. You will receive a prompt to enter values for version and package. Please enter the required values as in the screen shot below.
mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-spring -DremoteRepositories=http://static.appfuse.org/releases -DarchetypeVersion=2.0.2 -DgroupId=com.thea.airlines -DartifactId=airlines

entervalues (6K)

After Maven downloads the required files we receive a BUILD SUCCESSFUL message. Now let us open pom.xml under E:\theacodefactory\code\airelinesweb\airlines.
Now under dependencies, we will add struts dependency as in the screenshot below.
strutsdependency (4K)
Now in the command prompt change to the directory E:\theacodefactory\code\airelinesweb\airlines.

Run the command mvn packageso that it downloads the struts 2 and its dependent files.

Incase you face SQLException or any error related to database, search in pom.xml and edit MySQL user id and password as in the screenshot below. [We will discuss in later sections how to use another database]. As in the screenshot user is root and password is password.
mysqlconfig (6K)

Now execute the command mvn eclipse:eclipse command so that the project is configured to be used by Eclipse 3.3 for Java EE Developers. Now we have to export the Maven repository value to Eclipse classpath. To do that execute the command below.
mvn -Declipse.workspace=D:\javacode eclipse:add-maven-repo
Here D:\javacode is my workspace.
Open Eclipse 3.3 and create a new project as in the screenshot below.
eclipsenewproject (7K)

The Eclipse will show some errors are present in the project. To resolve it, right click on airlines project, choose properties, select validation, check "Override validation preferences" and then click on the "Disable All" button as in the screen shot.
disablevalidation (23K)
Now your project is setup with spring, struts and build using Maven. To create war files use the command mvn package and you will find airlines-.1.war under the folder E:\theacodefactory\code\airelinesweb\airlines\target.

View next section of this tutorial -- Struts 2 Action class using annotation in 5 minutes

 

 

Copyrights 2008 Thea Solutions
All rights reserved
Powered by 4creativeweb Solutions