Setup the environment needed to run the sample REST_lamp application for
which we provide the following:
This is perhaps the simplest setup for a RESTful project. The downside is
that there is no build automation tool such as Maven or Gradle which is
something you want for a bigger project.
Start with a freshly installed copy of Ubuntu 18.04 LTS (Bionic Beaver),
18.04.3 to be more exact.
4. Import the sample project into your workspace
-
Download the project file
into your Downloads folder.
-
Uncompress the file and move the contents into your Eclipse workspace.
$ cd ~/Downloads
$ gunzip REST_lamp_s2020.tar.gz
$ tar xvf REST_lamp_s2020.tar
$ mv REST_lamp <path_to_your_eclipse_workspace>
Go to "File > Import" and select "General > Existing Projects into Workspace"
Select the REST_lamp project. NOTE 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.mirrors.hoobly.com/tomcat/tomcat-8/v8.5.53/bin/apache-tomcat-8.5.53.tar.gz
$ gunzip apache-tomcat-8.5.53.tar.gz
$ tar xvf apache-tomcat-8.5.53.tar
$ sudo mv apache-tomcat-8.5.53 /opt/tomcat
$ cd /opt/tomcat/bin
$ ./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 servers 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 then "Run > Run"