In this post, we will create a basic Struts2 web application using Maven.
We will deploy it in Tomcat server or J2EE Preview.
If you need help downloading maven, you can refer to this post :
After Maven is installed, make sure JAVA_HOME is setup to your java installation folder and Maven bin folder is added to PATH variable. The instructions can again be found in post referred above.
Now, run the following from the command line :
mvn archetype:generate -DarchetypeCatalog=http://struts.apache.org/
This will start archetype catalog download in Interactive mode .. select option 1 here to choose Struts 2 Archetype – Blank.
Now provide the below for next options(you can add your own names here) :
Enter “Y” to confirm and your project will be ready.
Now go into the Struts2HelloWorld project directory and make sure it has the pom.xml. The eclipse project can be generated by running mvn eclipse:eclipse command from the project directory:
Import the project in eclipse by File -> Import -> Existing projects into workspace:
This is how the project structure would look like at this point :
If you deploy this on a server at this point and submit the url http://localhost:8080/Struts2HelloWorld, you would see the default output :
Struts is up and running…
Now, lets modify this for displaying Hello World instead..
Modify the HelloWorld.message in package.properties as below :
HelloWorld.message = Struts is up and running…
Also, replace the HelloWorld.jsp with below code :
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
If you try the url http://localhost:8080/Struts2HelloWorld now, you would get the Hello World message in the browser.
© 2015, www.topjavatutorial.com. All rights reserved. On republishing this post, you must provide link to original post