Back to: Java Struts Tutorials
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.
- Setup Java Development Kit (JDK)
- Setup Apache Tomcat
- Setup Eclipse (IDE)
- Setup Struts2 Libraries
Step 1 – Setup Java Development Kit (JDK)
- Download the latest version of Java SDK from Oracle’s Java site − Java SE Downloads.
- Install it and configure the setup.
- 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
Alternatively, IDEs can also be used such as – Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio
Step 2 – Setup apache Tomcat
- Download the latest version of Tomcat from https://tomcat.apache.org/ .
- Install it in your machine.
- Upseathe the Binary Distribution into any desired location of yours.
- For windows, it is by default in C:\apache-tomcat-6.0.33
- In Unix /usr/local/apachetomcat-6.0.33.
- 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:
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)
- Download the latest version of Eclipse IDE from https://www.eclipse.org/downloads.
- Install it in your machine.
- 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.
- 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 –
Step 4 – Setup Struts 2 Libraries
- We can download the latest version of Struts2 binaries from http://struts.apache.org/download.cgi.
- If you are a Windows user then download the .zip file or for Unix users, it is .tz file.
- Unzip the downloaded file in your desired location. (For example, C:\struts-2.2.3)
- The folder C:\struts-2.2.3\lib has all the required jar files in it.
- 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.