Struts & Eclipse - Example Webapps
(Free Web Tutorial)
by Michael Thomas
Struts Home Page
In this tutorial you will setup Eclipse IDE projects so that you
can edit and compile the Struts Example webapps that you optionally installed
with Struts.
Note: On the "Struts Home Page", you can download
the whole site (all content, tutorials & examples) !!!
This tutorial covers: Struts 2.0.11.1
running on Apache Tomcat
6.0.16 (as of 05/25/08)
Prerequisites
- Web App container that supports Struts 2.0.11.1:
Servlet API 2.4 - (ie: Tomcat 5.x or higher)
JSP API 2.0 - (ie: Tomcat 5.x or higher)
Java 5
- Note: On the home page of "Free Web Tutorials on Java & Web
Technologies" we have a tutorial to install Java JDK & Tomcat.
- Know how to Stop & Start the "Apache Tomcat" service.
- This tutorials has been tested in the following environment:
Date: 05/25/08
OS: Win XPro
JDK: jdk1.6.0_03
Objectives
- Setup an Eclipse project for the Struts Example webapps that come with
Struts so that you can edit & compile them.
Table of Contents (Struts Webapps)
I would setup an Eclipse project for each of these webapps so you can edit
& compile changes to files. The option is yours.
- struts2-showcase-2.0.11.1 - see examples in isolation (not a best
practices guide).
- struts2-blank-2.0.11.1 - good webapp to copy from if you are
creating a new Struts Webapp. Example of using English & Spanish language.
- struts2-mailreader-2.0.11.1 - a best practices Struts webapp
example.
- struts2-portlet-2.0.11.1 - (under
construction) I need to look at this webapp.
struts2-showcase-2.0.11.1 - Apache Strut's example web
app.
- Verify you have Tomcat's example webapp.
- Using Win Explorer find the Tomcat Webapp directory.
Possible directory:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps
- struts2-showcase-2.0.11.1 - this webapp exits (the directory) then you can
continue this tutorial.
- http://localhost:8080/struts2-showcase-2.0.11.1
- make sure Tomcat is running then verify this works!
- Create the Webapp
- Stop Tomcat
- Let's copy the existing web app so you can make changes without changing
the original web app.
- Go to the Tomcat webapps directory:
Ex: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\
- Make a copy of the directory "struts2-showcase-2.0.11.1" and name it:
myeclipse-struts2-showcase-2.0.11.1
- Verify the new webapp works
- Eclipse - Create a Java Project -
- Launch Eclipse
- File, New, Project, Java Project, Next
- Project Name:
myeclipse-struts2-showcase-2.0.11.1
- Contents: "Create project from existing source".
- Click "Next"
- Click "Browse" and locate the directory in the Tomcat WebApp
directory.
Click to select.
Ex Directory:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\myeclipse-struts2-showcase-2.0.11.1
- Folder: myeclipse-struts2-showcase-2.0.11.1
Click "OK"
- Click "Next"
- Remove a Source Folder - "WEB-INF/classes"
- FYI - In the "Sources" window the following source folder
exists: "WEB-INF/classes". The .java files are also located in the
"WEB-INF/src/java directory. Not sure why yet.
- Select: "WEB-INF/classes"
- Now in the Details window below, click the link "Remove
source folder 'classes' from build path:"
- On the "Java Settings" screen change the "Default output folder":
myeclipse-struts2-showcase-2.0.11.1/WEB-INF/classes
Click "Finish"
- WARNING READ THIS: If you see the prompt "The output folder has changed ...." click
"No".
If you click yes you will delete a needed directory.
- Compile errors - if we have some, let's see if the compiles
will be resolved with the "Build Path" steps.
- Eclipse - Build Path - add the Struts/Tomcat lib jars files.
- Right click on the project.
- Click "Build Path", "Configure Build Path", then
click the tab "Libraries"
- Check to make sure that the "JRE System
Library" is listed.
If not, click "Add Library", "JRE System
Library", "Next", "Finish".
Notes:
Under the tab "Order and Export" this lib file should be directly under
the WEB-INF/src directory.
You can't compile .java files without this library!!!
- Click "Add External JARs"
- Browse to the Tomcat common library directory.
Ex: C:\Program Files\Apache Software Foundation\Tomcat
5.5\common\lib
- Select all of the JAR files and click "Open".
- Click "OK" to leave the "Java Build Path" screen.
- You're finished.
struts2-blank-2.0.11.1 - Apache Strut's example web
app.
- Verify you have Tomcat's example webapp.
- Using Win Explorer find the Tomcat Webapp directory.
Possible directory:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps
- struts2-blank-2.0.11.1 - this webapp exits (the directory) then you can
continue this tutorial.
-
http://localhost:8080/struts2-blank-2.0.11.1
- make sure Tomcat is running then verify this works!
- Create the Webapp
- Stop Tomcat
- Let's copy the existing web app so you can make changes without changing
the original web app.
- Go to the Tomcat webapps directory:
Ex: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\
- Make a copy of the directory "struts2-blank-2.0.11.1" and name it:
myeclipse-struts2-blank-2.0.11.1
- Verify the new webapp works
- Eclipse - Create a Java Project -
- Launch Eclipse
- File, New, Project, Java Project, Next
- Project Name:
myeclipse-struts2-blank-2.0.11.1
- Contents: "Create project from existing source".
- Click "Next"
- Click "Browse" and locate the directory in the Tomcat WebApp
directory.
Click to select.
Ex Directory:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\myeclipse-struts2-blank-2.0.11.1
- Folder: myeclipse-struts2-blank-2.0.11.1
Click "OK"
- Click "Next"
- On the "Java Settings" screen change the "Default output folder":
myeclipse-struts2-blank-2.0.11.1/WEB-INF/classes
Click "Finish"
- WARNING READ THIS: If you see the prompt "The output folder has changed ...." click
"No".
If you click yes you will delete a needed directory.
- Compile errors - if we have some, let's see if the compiles
will be resolved with the "Build Path" steps.
- Eclipse - Build Path - add the Struts/Tomcat lib jars files.
- Right click on the project.
- Click "Build Path", "Configure Build Path", then
click the tab "Libraries"
- Check to make sure that the "JRE System
Library" is listed.
If not, click "Add Library", "JRE System
Library", "Next", "Finish".
Notes:
Under the tab "Order and Export" this lib file should be directly under
the WEB-INF/src directory.
You can't compile .java files without this library!!!
- Click "Add External JARs"
- Browse to the Tomcat common library directory.
Ex: C:\Program Files\Apache Software Foundation\Tomcat
5.5\common\lib
- Select all of the JAR files and click "Open".
- Click "OK" to leave the "Java Build Path" screen.
- You're finished.
struts2-mailreader-2.0.11.1 - Apache Strut's example web
app.
- Verify you have Tomcat's example webapp.
- Using Win Explorer find the Tomcat Webapp directory.
Possible directory:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps
- struts2-mailreader-2.0.11.1 - this webapp exits (the directory) then you can
continue this tutorial.
-
http://localhost:8080/struts2-mailreader-2.0.11.1
- make sure Tomcat is running then verify this works!
- Create the Webapp
- Stop Tomcat
- Let's copy the existing web app so you can make changes without changing
the original web app.
- Go to the Tomcat webapps directory:
Ex: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\
- Make a copy of the directory "struts2-mailreader-2.0.11.1" and name it:
myeclipse-struts2-mailreader-2.0.11.1
- Verify the new webapp works
- Eclipse - Create a Java Project -
- Launch Eclipse
- File, New, Project, Java Project, Next
- Project Name:
myeclipse-struts2-mailreader-2.0.11.1
- Contents: "Create project from existing source".
- Click "Next"
- Click "Browse" and locate the directory in the Tomcat WebApp
directory.
Click to select.
Ex Directory:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\myeclipse-struts2-mailreader-2.0.11.1
- Folder: myeclipse-struts2-mailreader-2.0.11.1
Click "OK"
- Click "Next"
- On the "Java Settings" screen change the "Default output folder":
myeclipse-struts2-mailreader-2.0.11.1/WEB-INF/classes
Click "Finish"
- WARNING READ THIS: If you see the prompt "The output folder has changed ...." click
"No".
If you click yes you will delete a needed directory.
- Compile errors - if we have some, let's see if the compiles
will be resolved with the "Build Path" steps.
- Eclipse - Build Path - add the Struts/Tomcat lib jars files.
- Right click on the project.
- Click "Build Path", "Configure Build Path", then
click the tab "Libraries"
- Check to make sure that the "JRE System
Library" is listed.
If not, click "Add Library", "JRE System
Library", "Next", "Finish".
Notes:
Under the tab "Order and Export" this lib file should be directly under
the WEB-INF/src directory.
You can't compile .java files without this library!!!
- Click "Add External JARs"
- Browse to the Tomcat common library directory.
Ex: C:\Program Files\Apache Software Foundation\Tomcat
5.5\common\lib
- Select all of the JAR files and click "Open".
- Click "OK" to leave the "Java Build Path" screen.
- You're finished.