Sample Project, Setup
1. Pre-requisite
Start with a clean installation of Linux, Ubunty 10.04
2. Install Java 8 from the command line
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
Verify Java version:
$ java -version
3. Configure Java environment
$ sudo apt-get install oracle-java8-set-default
4. Install Eclipse (Mars) and configure it
-
Download the Eclipse installer from
the Eclipse website.
The link will download the 64-bit version. If your computer has a 32-bit CPU, then
you can get the 32-bit downloader
here
-
Uncompress and unarchive the installer.
$ gunzip eclipse-inst-linux64.tar.gz | tar xvf
Navigate to ~/Downloads/eclipse-installer and then double click on the installer (eclispe-inst)
to run it. Select "Eclipse IDE for Java Developers" and complete the installation.
Start Eclipse
Go to Help > Install New Software
Select “Work with: Mars - http://download.eclipse.org/releases/mars”
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”
5. 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.
6. Install Tomcat 8 on your Ubuntu
$ cd ~/Downloads
$ wget http://mirrors.gigenet.com/apache/tomcat/tomcat-8/v8.0.33/bin/apache-tomcat-8.0.33.zip
$ unzip apache-tomcat-8.0.33.zip
$ sudo mv apache-tomcat-8.0.33 /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
7. 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 (java-8-oracle), then Finish. Close the Java Build Path
view by clicking on OK.
- Validate that a number of errors are gone.
8. Setup a runtime environment in Eclipse
- Go to Window > Preferences > Server > Runtime Environments
-
Click on Add to create a new Runtime, then select Apache Tomcat v8.0 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 OK.
With this the last error reported in the Problems view should be gone.
You're now ready to build and run the code.
9. 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.0 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.
10. 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
$Id: project-setup.html,v 1.1 2016/08/28 16:22:34 virgil Exp $
|