Sample Project, Setup
1. Pre-requisite
Start with a clean installation of Linux, Ubuntu 16.04
You can download the Ubuntu image we use to build our test environment
here.
2. Install Java 8 from the command line
$ sudo apt-get install default-jdk
Verify Java version:
$ java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.16.04.1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
3. Install Eclipse (Photon) and configure it
-
Download the Eclipse installer from
the Eclipse website.
The link will download the 64-bit version.
-
Uncompress and unarchive the installer.
$ gunzip eclipse-inst-linux64.tar.gz
$ tar xvf eclipse-inst-linux64.tar
Navigate to ~/Downloads/eclipse-installer and then double click
on the installer (eclipse-inst) to run it.
Select "Eclipse IDE for Java Developers" and complete the installation.
Launch Eclipse
Go to Help > Install New Software
Select “Work with: Photon - http://download.eclipse.org/releases/photon”
Select the “Web, XML, Java EE Development and OSGi Enterprise Development”
check box, then "Next"
Select the following from the multi-selection box:
- Eclipse Java EE Developer Tools
- Eclipse Java Web Developer Tools
- Eclipse Web Developer Tools
- JST Server Adapters
- JST Server Adapters Extensions
Accept the terms and “Finish”. NOTE: you may have to wait a few minutes
before the installation is complete.
4. Import the sample project into your workspace
- Go to File > Import and Select General > Existing Projects into Workspace
-
Select the project file you're importing (REST_lamp.zip). You'll see some errors
in the Problems view, however they will be resolved shortly, as you go through the next steps.
5. Install Tomcat 8 on your Ubuntu
$ cd ~/Downloads
$ wget http://apache.cs.utah.edu/tomcat/tomcat-8/v8.5.34/bin/apache-tomcat-8.5.34.zip
$ unzip apache-tomcat-8.5.34.zip
$ sudo mv apache-tomcat-8.5.34 /opt/tomcat
$ cd /opt/tomcat/bin
$ chmod 744 *sh
$ ./startup.sh
Verify that tomcat has started by pointing your browser
at http://localhost:8080 ... you should see
the Tomcat banner page. Now shutdown the server:
$ ./shutdown.sh
6. Configure build path
-
Right click on the project name and select Build Path > Configure Build Path,
then select the Libraries tab in the right pane.
- Select JRE System Library and then click Edit
-
Select the "Workspace Default JRE", then Finish. Close the
Java Build Path view by clicking on "Apply and Close".
- Validate that a number of errors are gone.
7. Setup a runtime environment in Eclipse
- Go to Window > Preferences then select Server > Runtime Environments
-
Click on Add to create a new Runtime, then select "Apache Tomcat v8.5" and leave the
"Create a new local server" box unchecked. Click on Next.
- Type /opt/tomcat in the "Tomcat installation path" text box. Click Finish.
- Dismiss the Preferences view by clicking on "Apply and Close".
-
Right click on the project name and select Properties then select
"Targeted Runtimes". Uncheck the box for "Apache Tomcat v8.0" and check
the box for "Apache Tomcat v8.5" then "Apply and Close".
With this the last error reported in the Problems view should be gone.
You're now ready to build and run the code.
8. Create a server where the code will be deployed
Now we have to create a real server on which the application will be deployed
and run. Multiple real server can use the same runtime environment, or you can
have multiple real servers each of them with their own runtime. For now let's
keep it simple, we'll go with a single runtime environment and a single real server.
-
Go to Window > Show View > Other expand Server and click on Servers; this
will open a new tab named Servers to your workbench. Right click in that
window and select New > Server. Select Apache Tomcat and then press the New icon.
-
Keep the host name as "localhost", select the "Apache Tomcat v8.5 Server" as the type,
name the server whatever you like (e.g. "My local tomcat"), and make sure the Server
runtime you installed is selected in the drop down list. Click Next, select the name
of the resource(s) that needs to be configured (REST_lamp in this example) on the server
and Add it to the Configured pane.
-
Click "Finish" and there should now be a server entry with the name you specified
in the "Servers" window.
9. Final touches
That's all. Now you can select Run > Run and the project will be built and deployed to the
local server. You can access the REST services at http://localhost:8080/REST_lamp/lamps
If you'd rather access the same services at http://localhost:8080/lamps -- which is how
the API specifies it -- then do the following:
-
Expand the server you created: you should see a number of files associated with the server,
such as catalina.policy, catalina.properties, etc.
-
Right click on server.xml and open it with a text editor. Scroll down to the line that
begins with "<Context" and edit the value of path from "/REST_lamp" to "/".
- Save and Run > Run
|