Struts 2 – Setup a Struts 2 Web Application in Maven

I follow the Struts 2 tutorial and setup a simple Struts 2 application.
Create Struts 2 Web Application Using Maven To Manage Artifacts and To Build The Application

I used the struts2-core version 2.2.1 and also added a maven-jetty-plugin for running the web application. But when i run mvn jetty:run, the following error is found.
java.lang.IllegalArgumentException: Javassist library is missing in classpath! Please add missed dependency!

It is found that in struts2-core version 2.2.1, the Javassist dependency was excluded in OGNL. So i have to add this dependency in the pom.xml by myself.

So here comes to the project details.
1. Create a new Maven project with the following pom.xml

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
						<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
					<requestLog implementation="org.mortbay.jetty.NCSARequestLog">


2. Put the following files in src/main/resources

  • log4j.dtd (Can be found inside log4j.jar – org/apache/log4j/xml/)
  • log4j.xml
  • struts.xml


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">

<log4j:configuration xmlns:log4j="">
    <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
       <layout class="org.apache.log4j.PatternLayout"> 
          <param name="ConversionPattern" value="%d %-5p %c.%M:%L - %m%n"/> 
    <!-- specify the logging level for loggers from other libraries -->
    <logger name="com.opensymphony">
    	<level value="DEBUG" />

    <logger name="org.apache.struts2">
    	 <level value="DEBUG" />
   <!-- for all other loggers log only debug and above log messages -->
        <priority value="INFO"/> 
        <appender-ref ref="STDOUT" /> 



<?xml version="1.0" encoding="UTF-8"?>
	"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

	<constant name="struts.devMode" value="true" />

	<package name="basicstruts2" extends="struts-default">
		<action name="index">



3. Create the following files

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" 
<display-name>Struts 2 Trial</display-name>






<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Basic Struts 2 Application - Welcome</title>
		<h1>Welcome To Struts 2!</h1>


4. The project hierarchy will look like this (You can ignore the META-INF)


5. Run mvn jetty:run and go to the URL http://localhost:8090/struts2-trial/index.action in the browser


Done =)

8 thoughts on “Struts 2 – Setup a Struts 2 Web Application in Maven”

    1. you mean u want to remove the maven-jetty-plugin? probably you can still build the project without any problem because the jetty plugin is for starting the java web application.


    1. sorry, didn’t get the meaning of your question. do you mean you want to deploy it to Apache? it cannot be done becoz it has to be run on Java app server like tomcat or jetty.


      1. ya i want to deploy this in Apache-tomcat
        can you brief me the steps to test the struts Action classes along with the interceptors and validation.xml files…?
        that means when testing the Action classes interceptors and validation should happens
        you can give a simple example…
        which jars needs to be used…?


      2. manual deployment to tomcat can be done by copying the .war to the tomcat webapp folder.

        if you want to automate the deployment, you can take a look on the Maven Tomcat Plugin

        About writing unit test, frankly, i haven’t done it before so i couldn’t give you any suggestions. but the following links maybe useful to u to get start.

        hope they can help. =)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.