Getting started with Apache Struts 2 , with Netbeans 6.1

adorableautomaticΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 5 χρόνια και 27 μέρες)

313 εμφανίσεις

Getting started with Apache Struts 2 , with Netbeans 6.1

There are plenty of guides that tell you how to start with struts 2, but most of them are incomplete or
don’t work. This guide even makes sure you have IDE JavaDoc support for struts 2 libraries. (Press Ctrl-
Space to get details about methods and classes in struts 2 libraries)

Download Struts 2 here :

http://struts.apache.org/download.cgi

Download the Full Distro, so that we get all libraries and docs. (docs are important if u want to have IDE
support help and tooltips and syntax)
 Full Distribution:
o
struts-2.0.11.2-all.zip
(91mb) [
PGP
] [
MD5
]
As of this writing , this is the latest version of Struts.

Download Netbeans 6.1 here :

http://www.netbeans.org/downloads/

or here :
http://dlc.sun.com.edgesuite.net/netbeans/6.1/final/

Download the full bundle (under the All column) size about 220 MB

Choose a folder for all your JAVA material that has NO SPACES in its path. Like C:\Java
“C:\Program Files” has a space, so it has some issues with the Sun Application Platform, which you might
need after development.

Other downloads :

[These are not necessary now, but just download them while working on this guide]
Eclipse for JavaEE Dev :
http://www.eclipse.org/downloads/

Eclipse IDE for Java EE Developers (163 MB)

Java Application Platform :
http://java.sun.com/javaee/downloads/index.jsp


App Platform + JDK†

Java Standard Edition [SE] :
http://java.sun.com/javase/downloads/index.jsp


JDK 6 Update 7

Install as follows :

This is how a pro I knew advised to set a comp up for Java EE Dev. You can install anywhere, but
the Guide will use these assume, this is how you’ve installed things.
0. Install Java SE (JDK 6 Update 7) to C:\Java\jdk1.6.0_07
and the packaged Java Runtime
Environment (Public JRE) to C:\Java\jre1.6.0_07
Note : No Spaces in the path
1. Extract struts-2.1.2-all.zip to C:\Java
. This will create a folder C:\Java \struts-2.1.2

2. Install Netbeans 6.1 to C:\Java\NetBeans6.1
.[ Note: There is no space in the path]
Along with the Apache Server packed with netbeans, you need to press the customize or
advanced button to install the packaged apache server, and to set your own path.
3. After Netbeans , the packaged apache server will ask for path give C:\Java ApacheTomcat6.0.16

Note: No Space here also
My comp is set up like this
C:\Java\ ApacheTomcat6.0.16 - from netbeans-6.1-ml-windows setup
C:\Java\ NetBeans6.1 - from netbeans-6.1-ml-windows setup
C:\Java\ jdk1.6.0_04 - from jdk-6u4-windows-i586-p setup
C:\Java\ jre1.6.0_04 - from jdk-6u4-windows-i586-p setup
C:\Java\ struts-2.1.2 - from struts-2.1.2-all.zip extract
C:\Java\ Eclipse - from eclipse-jee-ganymede-win32 setup
C:\Java\ AP - from java_app_platform_sdk-5_05-windows setup
C:\Java\glassfish-v2ur2 - from java_app_platform_sdk-5_05-windows setup
C:\Java\Nwork - Netbeans WorkSpace
C:\Java\Ework -Eclipse WorkSpace
C:\Java\ StrutsBlank -Contents of struts2-blank-2.1.2.war file

I Created my POJOs i.e Plain Old Java Objects – Business model classes and helper classes in Eclipse, just
to know whats there in the IDE, and compiled them to JAR files.
Then I used these JARs in the WebApplication fully done in NetBeans. But leave that, we’ll see how to
set up struts 2 and netbeans, fully dev-ready
Important Stuff (so don’t deviate!) :

Create a new Web Application in NetBeans

File-> New Project..-> Category:Web -> Projects:Web Application


Choose Java EE5 as the Java EE Version, and Apache Tomcat 6.0.16 as the Server (which we installed
from the netbeans setup itself) If the server is not there Add it, choosing the path C:\Java\
ApacheTomcat6.0.16 as the home directory of the server.

DO NOT ADD ANY Frameworks like struts of JSF now, you can add ‘em later. Click Finish.

Go to C:\Java\ struts-2.1.2\ apps
folder. Open WinZip.
Drag - Drop the struts2-blank-2.1.2.war onto the WinZip window.
Press the Extract button on the top of the WinZip window and extract to C:\Java\ StrutsBlank
. You must
type this in cause “StrutsBlank” is a folder WinZip will have to create to place the contents of the WAR
file.
Come back to NetBeans, Go to Tools-> Libraries, Click on New Library.. button

Type in “Struts2Library” as name and Press OK
Then Press Add J
AR/Folder.. button and in the open file dialog , navigate to C:\Java\StrutsBlank\WEB-
INF\lib

Select all the JAR files in there pressing the SHIFT key, and add ‘em.


Go to Javadoc Tab, Press Add Z
ip/Folder button and in the Open Folder Dialog navigate to
C:\Java\struts-2.1.2\docs\struts2-core
and select apidocs folder and click A
dd Zip/Folder button in the
dialog

Press Ok that closes the Library Manager dialog box.
Now Right Click the Libraries folder in the Projects window in the netbeans IDE, select Add Library.. and
add the Struts2Library.

Navigate to C:\Java\StrutsBlank
in windows explorer and Drag-Drop the C:\Java\StrutsBlank\example

folder into the NetBeans Web Pages treenode
Delete the Web Pages\WEB-INF\web.xml in netbeans
Drag-Drop the C:\Java\StrutsBlank\WEB-INF\web.xml
file into the NetBeans Web Pages\WEB-INF
treenode
Delete the Web Pages\ index.html in netbeans
Drag-Drop the C:\Java\StrutsBlank\index.html
file into the NetBeans Web Pages treenode
Right-Click the Source Packages treenode in NetBeans, and New->Java Package, and type in “example”
as the package name. This name is necessary to allow the blank app to get working.
Drag-Drop all the 6 files in C:\Java\StrutsBlank\WEB-INF\src\java\example
onto the Source
Packages\example treenode
Drag-Drop the 2 XML files in C:\Java\StrutsBlank\WEB-INF\src\java example.xml and struts.xml
to the
Source Packages treenode[ such that they come under the default package]
Thus we have moved all XML and .jsp and .java files from blank app to netbeans. After all that your
Project Explorer will belike :

Build using F11 key.
NetBeans will have created two folders for you build and dist.
build\web\WEB-INF\lib and build\web\WEB-INF\classes are automatically created and populated with
the JAR files and .class files.
dist will have the WAR file that u can use to distribute your web app.
Run using F6 key to see the output.
If any error while building or running, Save everything, close netbeans AFTER closing the server by
pressing the green square stop button in the serve tab of the netbeans IDE. Then go to task manager
close all java.exe process and any and all server process also and reopen netbeans and press f6.

I localized to Tamil. You should see Spanish instead of Tamil in the output.