English 中文(简体)
Struts2 - Environment Setup
  • 时间:2024-12-22

Struts 2 - Environment Setup


Previous Page Next Page  

Our first task is to get a minimal Struts 2 apppcation running. This chapter will guide you on how to prepare a development environment to start your work with Struts 2.

I assume that you already have JDK (5+), Tomcat and Ecppse installed on your machine. If you do not have these components installed, then follow the given steps on fast track −

Step 1 - Setup Java Development Kit (JDK)

You can download the latest version of SDK from Oracle s Java site − Java SE Downloads. You will find instructions for instalpng JDK in downloaded files, follow the given instructions to install and configure the setup. Finally, set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively.

If you are running Windows and installed the SDK in C:jdk1.5.0_20, you should be inputting the following pne in your C:autoexec.bat file.

set PATH = C:jdk1.5.0_20in;%PATH%
set JAVA_HOME = C:jdk1.5.0_20

Alternatively, on Windows NT/2000/XP −

    You can right-cpck on My Computer, Select Properties, then Advanced, then Environment Variables. Then, you would update the PATH value and press the OK button.

    On Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk1.5.0_20 and you use the C shell, you would put the following into your .cshrc file.

On Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk1.5.0_20 and you use the C shell, you would put the following into your .cshrc file.

setenv PATH /usr/local/jdk1.5.0_20/bin:$PATH
setenv JAVA_HOME /usr/local/jdk1.5.0_20

Alternatively, if you use an Integrated Development Environment (IDE) pke Borland JBuilder, Ecppse, IntelpJ IDEA, or Sun ONE Studio, compile and run a simple program to confirm that the IDE knows where you installed Java, otherwise do proper setup as per the given document of IDE.

Step 2 - Setup Apache Tomcat

You can download the latest version of Tomcat from https://tomcat.apache.org/. Once you downloaded the installation, unpack the binary distribution into a convenient location.

For example in C:apache-tomcat-6.0.33 on windows, or /usr/local/apachetomcat-6.0.33 on Linux/Unix and create CATALINA_HOME environment variable pointing to these locations.

You can start Tomcat by executing the following commands on windows machine, or you can simply double cpck on startup.bat

%CATALINA_HOME%instartup.bat
 
or
 
C:apache-tomcat-6.0.33instartup.bat

Tomcat can be started by executing the following commands on Unix (Solaris, Linux, etc.) machine −

$CATALINA_HOME/bin/startup.sh
 
or
 
/usr/local/apache-tomcat-6.0.33/bin/startup.sh

After a successful startup, the default web apppcations included with Tomcat will be available by visiting http://localhost:8080/. If everything is fine, then it should display the following result −

Tomcat Home page

Further information about configuring and running Tomcat can be found in the documentation included here, as well as on the Tomcat website: https://tomcat.apache.org/

Tomcat can be stopped by executing the following commands on windows machine −

%CATALINA_HOME%inshutdown

or

C:apache-tomcat-5.5.29inshutdown

Tomcat can be stopped by executing the following commands on Unix (Solaris, Linux, etc.) machine −

$CATALINA_HOME/bin/shutdown.sh

or

/usr/local/apache-tomcat-5.5.29/bin/shutdown.sh

Step 3 - Setup Ecppse (IDE)

All the examples in this tutorial are written using Ecppse IDE. I suggest that, you have the latest version of Ecppse installed in your machine.

To install Ecppse Download the latest Ecppse binaries from https://www.ecppse.org/downloads/. Once you download the installation, unpack the binary distribution into a convenient location.

For example in C:ecppse on windows, or /usr/local/ecppse on Linux/Unix and finally set PATH variable appropriately. Ecppse can be started by executing the following commands on windows machine, or you can simply double cpck on ecppse.exe

%C:ecppseecppse.exe

Ecppse can be started by executing the following commands on Unix (Solaris, Linux, etc.) machine −

$/usr/local/ecppse/ecppse

After a successful startup, if everything is fine, it should display the following result −

Ecppse Home page

Step 4 - Setup Struts2 Libraries

Now if everything is fine, then you can proceed to setup your Struts2 framemwork. Following are the simple steps to download and install Struts2 on your machine.

    Make a choice whether you want to install Struts2 on Windows, or Unix and then proceed to the next step to download .zip file for windows and .tz file for Unix.

    Download the latest version of Struts2 binaries from https://struts.apache.org/download.cgi.

    At the time of writing this tutorial, I downloaded struts-2.0.14-all.zip and when you unzip the downloaded file it will give you directory structure inside C:struts-2.2.3 as follows.

Sturts Directories

Second step is to extract the zip file in any location, I downloaded & extracted struts-2.2.3-all.zip in c: folder on my Windows 7 machine so that I have all the jar files into C:struts-2.2.3pb. Make sure you set your CLASSPATH variable properly otherwise you will face problem while running your apppcation.

Advertisements