In this tutorial, I am going to tell you how to set up the environment and start developing Java Server Pages and Servlets. Here are the things you’ll need:
- JDK (Java Development Kit) – At the time of writing version 8 is the latest, use the latest one.
- Java Application Server
- Java Integrated Development Environment
Let’s go step by step and set up the development environment.
Java Development Kit
You can download the JDK from here.
Java Development Kit or JDK for short is the fundamental requirement for any sort of development related to Java. Go to the link, accept the license agreement and select the version according to your OS. Once it is downloaded, start installing it with the default options. The default installation path may look like “C:\Program Files\Java\jdk*version number*”. It may take some time to download and complete the installation. After the JDK installation completes, the installer gives you the option to install JRE – Java Runtime Environment. Complete that installation as well.
Now if you are running an x64 OS, you are going to need to set up the environment variables so that you can work with Java through your command prompt. Here is how you do it:
- Right-click “My Computer” and Click “Properties”.
- Click on “Advanced System Settings”.
- In the newly opened dialogue box click on “Environment Variables”.
- In the System Variable section click on the “Path” and edit it.
- Append the Java installation directory path to the path variable.
- The path looks like this “C:\Program Files\jdk1.8.0_20\bin”
- Click OK and OK again.
- Now restart your computer.
- Once this is done, you need to verify your installation.
- Open up a command prompt and type in “java -version” and it should return the java version, the JRE version and the java server VM version.
- Now type “javac -version” and it should return the version of java.
- If it doesn’t return any value then you need to check the environment variables again.
Installing Java Application Server
To keep things simple we are going to download and install Apache Tomcat for this series. Get Apache Tomcat from here. At the time of recording Tomcat, 9 is the latest version and you should get the latest version yourself.
Scroll down to the binary distributions and select the one appropriate for your operating system. Let the download complete and start the installer.
- Click the First Next and Agree to the License Agreement.
- Choose “Full” from the drop-down in the component selection dialog box. Make sure that the “Service Startup” is checked under Tomcat.
- While configuring remember that Tomcat listens on port 8080, you can change that but try to leave it at 8080 if that port isn’t being used by any other program.
- Remember to keep such an easy username and password that you can remember, maybe write it down.
- If you have installed the JRE and JDK on their default paths, you can continue through this step.
- Leave the default installation path and continue.
After this the installation will begin and when it completes it will give you two options. Uncheck “Show Readme” if you want to and click on finish. Your Apache Tomcat is installed. To verify this installation:
- Open your browser.
- Type in http://localhost:8080 (this is where the whole server is running).
- If an Apache Tomcat page is displayed when your installation has gone well.
You can configure the server to a great extent, but if you don’t know much about the server then you better leave it with the default options. Just go to the Windows Services Dashboard and stop the Apache Tomcat Service, which we will start from the IDE later.
Java Integrated Development Environment
For this series, we are going to use Eclipse. Head on to http://www.eclipse.org and go to the “downloads” section. Here you want to make sure that you download the IDE for the Java EE package. It is very important to download as it has built-in support for JSP and Servlets. Download the 32 bit or 64 bit version according to your operating system. Clicking on the apt link will take you to a whole page of options but just go to the left and click the download button. Once prompted click save and download it to your specified directory. Now:
- Go to the Download Directory.
- Right click the downloaded zip file and unzip it to the folder of your choice.
- Now go to the extracted folder and run the eclipse.exe
- Eclipse will prompt you to select the workspace folder (this folder is where the eclipse will store all the projects and applications).
Now let’s connect Eclipse with Tomcat, which will make it easy for us to install our apps on Tomcat.
- In Eclipse, in the bottom center, there is a servers tab.
- Click on the link below to create a new server.
- As we are using Apache Tomcat, make sure to select the right version from the list.
- Click Next and now tell Eclipse where is your Apache Tomcat installed.
- Click Finish.
Now you’ll see the server listed in below. You can just right click on it and click on start server to get the server up and running. You can view the server information on the console window.
Now we are ready to start building JSP and Servlets. In the next tutorial, I am going to teach you the basics of JSP. See you then.