Creating a new struts2 project in Eclipse with Struts2-archetype-starter using m2eclipse

Last year I created my own struts2 project with help of m2eclipse. It was very simple. I just had to create a maven project and select “Struts 2 Starter” archetype from the catalog. It created a simple struts2 project for integrating it with spring, sitemesh etc. So when I had to start on a new struts2 project I was happy I updated my m2eclipse (it had been a long time after all) and tried to follow the same steps. However I could not find my old struts2 starter archtype, and so the time of frustration started.

After many hours of searching I could not get my project set up. I tried adding a new archtype using values from http://struts.apache.org/2.2.3/docs/struts-2-maven-archetypes.html , but it was no avail I kept getting some exception. Then I finally realized that the struts2 archetype repository does not contain the archetype files anymore. You can try finding the archetypes in http://people.apache.org/builds/struts/<version>/m2-staging-repository/

Once the realization dawned I started looking for new repository and finally found it on this page

http://mavenhub.com/mvn/central/org.apache.struts/struts2-archetypes/2.2.3

The struts2-arhetype-starter for 2.2.3 can be found in http://repo1.maven.org/maven2

Now finally the last bit that comprises of steps to create the struts2 project with m2eclipse

  1. Open your eclipse and click on File → New → Project
  2. Assuming you have m2eclipse installed select Maven → Maven Project in the new Project wizard.
  3. Click on Next twice and you will arrive on Select An Archetype screen.                                                              
  4. Click on Add Archetype button and supply following value                                                                     Archetype Group Id – org.apache.struts
    Archetype Artifact Id – struts2-archetype-starter
    Archetype Version –  2.2.3
    Repository Url - http://repo1.maven.org/maven2                                                                                        
  5. Click on OK.
  6. Now in Catalog Drop down select “All Catalog”. In filter type “org.apache.struts”. The newly added “struts2-archtype-starter” will show up in pane below. Select it and click Next                         
  7. On next screen specify groupid, artifactid, version and package for the application you wish to create.                                                                                                                                                                                            
  8. Click on finish and enjoy :) .

 

Print Friendly

About Niraj Singh

I am CEO and CoFounder of a startup "Aranin Software Private Limited, Bangalore. I completed my graduation in 2002 as an Aerospace Engineer from IIT Kharagpur. I love working on new ideas and projects and recently released my first open source project JaiomServer "http://jaiomserver.org". I have 9 years of experience in IT industries most of which I have spent in developing community applications for various clients using java. Some of the sites in which I have actively involved with are hgtv.com, food.com, foodnetwork.com, pickle.com, diynetwork.com etc.
This entry was posted in eclipse, Java, m2eclipse, maven, mvc framework, Struts2, tutorial and tagged , , , . Bookmark the permalink.

14 Responses to Creating a new struts2 project in Eclipse with Struts2-archetype-starter using m2eclipse

  1. Rudolph says:

    I know this web page provides quality dependent articles and extra
    data, is there any other website which provides these kinds of stuff
    in quality?

  2. Trung says:

    I have create project
    but when run, it’s show warning:
    ***************************************************************************
    * WARNING!!! *
    * *
    * >>> ActionContextCleanUp <<>> FilterDispatcher <<< is deprecated! Please use the new filters! *
    * *
    * This can be a source of unpredictable problems! *
    * *
    * Please refer to the docs for more details! *
    * http://struts.apache.org/2.x/docs/webxml.html *
    * *
    ***********************************************************************

    Please help on the issue.

    • Niraj Singh says:

      Hi Trung,

      You don’t have to delete ActionContextCleanUp listing

      1. Please revert back your change.
      2. Search for org.apache.struts2.dispatcher.FilterDispatcher in your web.xml and replace it with org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

      It is only filter that has changed. Please let me know if this fixes your issue.

      Regards
      Niraj

  3. Niraj Singh says:

    Hi Trung,

    Thanks for bringing this up. FilterDispatcher has been deprecated since struts 2.1.3 version. Struts2 now provides a new filter called StrutsPrepareAndExecuteFilter. To fix your issue open your web.xml and replace the following

    
       <filter>
            <filter-name>action2</filter-name>
            <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        </filter>
    

    with

    
       <filter>
            <filter-name>action2</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>
    

    Regards Niraj

  4. Trung says:

    hi Nirai !
    I have another case.
    ***************************************************************************
    WARNING!!!
    * >>> ActionContextCleanUp <<< is deprecated! Please use the new filters!
    * This can be a source of unpredictable problems!
    * Please refer to the docs for more details!
    * http://struts.apache.org/2.x/docs/webxml.html
    ***************************************************************************
    I have try delete ActionContextCleanUp in web.xml but the problem remains.

    Please help on the issue.
    Thanks !

  5. If some one needs expert view concerning blogging and site-building then i
    suggest him/her to visit this webpage, Keep up the nice
    work.
    homesecuritycompaniesechnology.webs.com recently posted…homesecuritycompaniesechnology.webs.comMy Profile

  6. Trung says:

    Hi ! Niraj Singh,
    I have create project but when run, it’s show warning:
    **************************************************************************
    * WARNING!!!
    * >>> ActionContextCleanUp <<>> FilterDispatcher <<>> FilterDispatcher <<>> ActionContextCleanUp <<< is deprecated! Please use the new filters!
    Thanks you !

  7. Trung says:

    Hi ! Niraj Singh,
    I have create project but when run, it’s show warning:
    FilterDispatcher is deprecated! Please use the new filters!
    I have search for org.apache.struts2.dispatcher.FilterDispatcher in your web.xml and replace it with org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter => Fix OK !
    But
    still the case :
    ActionContextCleanUp is deprecated! Please use the new filters!

    Please help on the issue.
    Thanks !

    • Niraj Singh says:

      Hi Trung,

      Sorry, did not understand your problem. So basically we are using sitemesh along with struts2. If you want to use actioncontext within sitemesh then you have to use actioncontextcleanup filter. But since it is deprecated so you can remove it all together and use StrutsPrepareFilter and StrutsExecueFilter in tandem. So here are the steps.

      1. Remove the ActionContextCleanUp filter listing and mapping.
      2. Replace the sitemesh page filter com.opensymphony.sitemesh.webapp.PageFilter with com.opensymphony.sitemesh.webapp.SiteMeshFilter
      3. Remove StrutsPrepareAndExecuteFilter altogether if you want to use sitemesh.
      3. Adde two new filters StrutsPrepareFilter and StrutsExecueFilter.
      4. So now order of filters should be StrutsPrepareFilter->SiteMeshFilter->StrutsExecueFilter
      5. Change the filter mapping to reflect the name changes.

      After all the changes your web.xml should have following filters listed.

       <filter>
               <filter-name>StrutsPrepareFilter </filter-name>
               <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
      </filter>
      <filter>
      	<filter-name>sitemesh</filter-name>
      	<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
      </filter>
      <filter>
      	<filter-name>StrutsExecuteFilter</filter-name>
      	<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
      </filter>
      
      <filter-mapping>
      	<filter-name>StrutsPrepareFilter</filter-name>
      	<url-pattern>/*</url-pattern>
      </filter-mapping>
      
      <filter-mapping>
      	<filter-name>sitemesh</filter-name>
      	<url-pattern>/*</url-pattern>
              <dispatcher>REQUEST</dispatcher>
      	<dispatcher>FORWARD</dispatcher>  
      </filter-mapping>
      
      
      <filter-mapping>
      	<filter-name>StrutsExecuteFilter</filter-name>
      	<url-pattern>/*</url-pattern>  			
      </filter-mapping>

      This worked for me, Please let me know if this fixes the warning.

      Regards
      Niraj

  8. Trung says:

    Hi ! Niraj Singh
    Thanks for the help !
    The above issues have been resolved.