02 - JSP Development Environment Set Up

2.1 What you need for JSP development environment

We would need an environment where we can develop and run web applications having JSP. By environment we mean to install all the required software and tools. In this chapter we will discuss how to set up JSP development environment.

Following tools and software are needed.

· Java.

This step involves

- downloading and installing Java version 7

- setting environment variables (JAVA_HOME and PATH) appropriately.

All the details are covered in Section 2.2.

· Apache Tomcat web server.

This step involves downloading a server that implements the JSP APIs. It is covered in Section 2.3

· Eclipse ( Integrated Development Environment Set Up)

This step involves installation of Eclipse IDE. Refer section 2.4 for more details.

· Tomcat Integration with Eclipse

This section is more of integration of tomcat with Eclipse so it can be managed from eclipse itself. Details available in section 2.5

· Verify the JSP development setup.

This step involves verification of the installation.

2.2 Download and install Java

Java is available in two editions (Standard Edition J2SE and Enterprise Edition J2EE ).For J2EE features like EJB, JMS,CDI etc , we would need Enterprise Edition(J2EE) but web applications having JSP and servlets can work with Standard Edition (J2SE) as well.

This entire tutorial is based on JSP so we will download and install java standard edition.

Java is freely available for download for all operating systems on Oracle’s Java website so you need to download the latest version from http://www.oracle.com/technetwork/java/javase/downloads

Follow below steps to install both JDK and JRE.

(JDK is java development kit required to develop the programs where as JRE is java runtime environment needed to run the programs )

In this tutorial I will follow the instructions for Windows Operating System. I have downloaded and installed java version 7 (refer below figure).

         

Download the executable file depending on operating system (windows 32 bit or windows 64 bit )and install it. This is quite simple but one thing that you need to do is setting the environment variables.

Below are the screens that you will see while installing Java on your machine.

         

Change the path on next screen if you want to (highlighted in below figure) . I have installed it at C:\Program Files (x86)\Java\jdk_1.7.0_67 location

         

 

         

 

         

Click Close.

Now you need to create and update below environment variables.

a)JAVA_HOME – Create a new environment variable JAVA_HOME and set its value to the installation directory of Java. For example if you have installed it in “C:\Program Files (x86)\Java\jdk1.7.0_67“ , you need to set its value as C:\Program Files (x86)\Java\jdk1.7.0_67

b) PATH- This is an existing environment variable and you just need to update it. Add the JAVA_HOME variable with bin.

Example – if JAVA_HOME is set to C:\Program Files (x86)\Java\jdk1.7.0_67 then Path variable will be updated with

   PATH=%PATH%;C:\Program Files (x86)\Java\jdk1.7.0_67/bin;

Alternatively

   PATH=%PATH%;%JAVA_HOME%/bin;

Other way to set the environment variable on windows platform is

Right Click On My ComputeràPropertiesàAdvanced system settingsàEnvironment Variables

You can add it either as a User variable or a system variable. Only difference is that System Variables will be available to all users of the system.

Other way is to add below lines in C:\autoexec.bat

set JAVA_HOME= C:\Program Files (x86)\Java\jdk1.7.0_45

set PATH=%PATH%;%JAVA_HOME%/bin;

Note - C:\Program Files (x86)\Java\jdk1.7.0_45 is example value. You need to use you own java installation directory path

Verification- You can verify the java installation by opening a command prompt and type a java . If everything is correct, it will show you several java options (refer below figure)

         

2.3 Apache Tomcat web server

We would need a stable and open source web server which supports JSP specifications. There are several options available but in this tutorial we will use Apache Tomcat.

Tomcat is actually composed of a number of components and containers including a Tomcat JSP engine, servlet Container and a variety of different connectors, but its core component is called Catalina. One important thing to be noted is Tomcat is a web server and not an application server.

Tomcat is freely available and can be downloaded from http://tomcat.apache.org/download-70.cgi

Note – There are several versions of tomcat and java are available so make sure you download compatible versions.

Steps to download and configure Tomcat

a) Once tomcat web server is downloaded, unzip it to the location of your choice. I use the top level of the D drive, resulting in D:\apache-tomcat-7.0.41 . By default tomcat is configured to run on port 8080 so it will be accessed by http://localhost:8080

         

b) Create a new environment variable CATALINA_HOME and set its value to the apache tomcat installation directory. In my case it will be D:\apache-tomcat-7.0.41

c) To start and stop the server, you need to use the batch files available in %CATALINA_HOME%/bin

o startup.bat to start the server

o shutdown.bat to stop the server

   

If you hit an error while starting server a saying “java_home /jre_home” is not set means you have not configured JAVA_HOME as described in section 7.2

 

Verification

Start the server using D:\apache-tomcat-7.0.41/bin/startup.bat and hit http://localhost:8080 in the browser. You should see page like below.

        

2.4 Eclipse - Integrated Development Environment

We can write JSP using any text editor but several IDE are freely available. I would encourage use of IDE because IDE provides us several features like -

a) we can manage the Tomcat,

b) develop programs and web application

c) need not to remember the exact methods and their signatures

d) compilation errors are clearly highlighted

 

There are several IDEs available like NetBeans, Eclipse etc. We will use Eclipse in this tutorial.

Download the latest eclipse version (Eclipse Kepler) from http://www.eclipse.org/downloads/packages/release/Kepler/SR2 and unzip it in directory of your choice . You need to download Eclipse IDE for Java EE Developers and not Eclipse Standard

I normally unzip into the top level of the D drive, resulting in D:\ eclipse-standard-kepler-SR2-win64

Start Eclipse Start eclipse by clicking eclipse.exe available in eclipse installation directory.

         

Once eclipse starts it will ask for a workspace. You can create one folder of your own choice and give the path of that folder. Workspace is basically a folder where eclipse will create all of your projects.

2.5 Tomcat Integration with Eclipse

As I mentioned earlier, tomcat can be managed with eclipse IDE and in this section we will discuss how to integrate tomcat with eclipse.

To do so

a) Go to Windows àPreferencesàServersàRuntime Environments àAdd in eclipse.

b) On click of Add , a new window will be opened (refer below). From the list of Tomcat servers, select “Apache Tomcat v7.0” and click Next

        

c) Select the path of Tomcat installation directory

         

Start and Stop Tomcat server from Eclipse

Click on Servers tab at bottom. Click on Green Arrow icon to start the server and Red square icon to stop.

         

Server console log can be seen in eclipse console. Once server is started, verify it by hitting http://localhost:8080 in browser.

Like us on Facebook