Tuesday, October 11, 2011

Easiest way to startup a Struts project with Eclipse IDE


All you need is the latest Struts 2 distribution and Eclipse IDE already installed on your computer.
Inside the struts 2 distribution, navigate to folder 'apps' and you'll find a war file named struts2-blank.war. This file contains basic structure of directories, files, and libraries, i.e. web.xml, struts.xml, WEB-INF etc to start a dynamic web-apps project with Eclipse. So you don't need to worry about them anymore and thus you can focus on implementing your application requirement.
Extract the file into a particular location of your choice, and then import it into Eclipse as a new project. 
That's it.... no big deal.
Once you import the file and it become a new project, you can start to add classes, web pages and files that you need. You can even run it before adding anything at all since it's actually a fully valid web project.
In case you have any doubt on how to import struts2-blank.war into Eclipse, here are steps in detail:
  1. In Eclipse, click File – Import

  2. Select 'WAR file' and click Next


  3. Browse the file 'struts2-blank.war', enter the project name (e.g. 'super web'), choose target container (e.g. Apache Tomcat v6.0, if it's not there then click New to select a new container, this container must be installed beforehand), then click Next.



  4. Deselect all library above and click Finish... and it's done


beautifully easy.... isn't it...
Now, if you run this 'super web' project, here's what you got: 


So as you can see it's already runnable without any glitch and now you can start building your application.