Struts 2 Environment Setup

Java Struts 2 Environment Setup

In this article, I am going to discuss the Java Struts 2 Environment Setup in detail. Please read our previous article where we discussed Struts 2 Architectures and Flow. At the end of this article, you will understand the following pointers in detail.

  1. Setup Java Development Kit (JDK)
  2. Setup Apache Tomcat
  3. Setup Eclipse (IDE)
  4. Setup Struts2 Libraries
Step 1 – Setup Java Development Kit (JDK)
  1. Download the latest version of Java SDK from Oracle’s Java site − Java SE Downloads.
  2. Install it and configure the setup.
  3. Set PATH and JAVA_HOME variables for referring to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively.

For Windows user –
set PATH = C:\jdk1.5.0_20\bin;%PATH% (if SDK is installed in C:\jdk1.5.0_20)
set JAVA_HOME = C:\jdk1.5.0_20

For Unix User –
setenv PATH /usr/local/jdk1.5.0_20/bin:$PATH ( if SDK is installed in /usr/local/jdk1.5.0_20)
setenv JAVA_HOME /usr/local/jdk1.5.0_20

Java Struts 2 Environment Setup

Alternatively, IDEs can also be used such as – Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio

Step 2 – Setup apache Tomcat
  1. Download the latest version of Tomcat from https://tomcat.apache.org/ .
  2. Install it in your machine.
  3. Upseathe the Binary Distribution into any desired location of yours.
  4. For windows, it is by default in C:\apache-tomcat-6.0.33
  5. In Unix /usr/local/apachetomcat-6.0.33.
  6. Create a CATALINA_HOME environment variable that points to those locations.

For Windows user –
Run the following command in your terminal
%CATALINA_HOME%\bin\startup.bat
Or,
C:\apache-tomcat-6.0.33\bin\startup.bat
Double click on the startup.bat

For Unix User –
Run the following command in your terminal
$CATALINA_HOME/bin/startup.sh
Or,
/usr/local/apache-tomcat-6.0.33/bin/startup.sh

After executing the above commands in your system(Windows/ Unix), if you go to the default browser i.e. http://localhost:8080/ (where 8080 is the default port number), it should display the below result:

Setup apache Tomcat to develop Struts 2 application

To stop Tomcat execution run the following commands –

For Windows User –
%CATALINA_HOME%\bin\shutdown
or,
C:\apache-tomcat-5.5.29\bin\shutdown

For Unix User –
$CATALINA_HOME/bin/shutdown.sh
or,
/usr/local/apache-tomcat-5.5.29/bin/shutdown.sh

Step 3 – Setup Eclipse (IDE)
  1. Download the latest version of Eclipse IDE from https://www.eclipse.org/downloads.
  2. Install it in your machine.
  3. Update the Binary Distribution into any desired location of yours. For windows, it is by default in C:\eclipse and in Unix /usr/local/eclipse.
  4. Set the PATH variable correctly.

For Windows users –
Run the following command in your terminal
%C:\eclipse\eclipse.exe
Double click on the eclipse.exe

For Unix User –
Run the following command in your terminal
$/usr/local/eclipse/eclipse

If all go well, then it must display the below page –

Setup Eclipse (IDE)

Step 4 – Setup Struts 2 Libraries
  1. We can download the latest version of Struts2 binaries from http://struts.apache.org/download.cgi.
  2. If you are a Windows user then download the .zip file or for Unix users, it is .tz file.
  3. Unzip the downloaded file in your desired location. (For example, C:\struts-2.2.3)
  4. The folder C:\struts-2.2.3\lib has all the required jar files in it.
  5. The folder C:/struts-2.2.3/apps contains all the war files in it.

Note: You must need to set the CLASSPATH variable properly, otherwise some execution-related problems of the web application will occur.

In the next article, I am going to discuss the steps to create a Struts 2 Application. Here, in this article, I try to explain Java Struts 2 Environment Setup and I hope you enjoy this Java Struts 2 Environment Setup article.

Leave a Reply

Your email address will not be published. Required fields are marked *