Home
> HowTos, Ubuntu > Set up Eclipse and Tomcat 7 on Ubuntu 12.10 to create Java RESTful Web Services with Jersey
Set up Eclipse and Tomcat 7 on Ubuntu 12.10 to create Java RESTful Web Services with Jersey
- Install Eclipse and Tomcat 7 by running in a terminal:
sudo apt-get install eclipse tomcat7 -y
- assign the tomcat7 group to your user. Assuming your username is pippo, run:
sudo adduser pippo tomcat7
Note: you need to log out and log back in for the changes to take effect.
- stop the system-wide Tomcat by running:
/usr/share/tomcat7/bin/shutdown.sh
- prevent the system-wide Tomcat from automatically starting at boot by running:
sudo update-rc.d tomcat7 disable
- install WTP (Web Tools Platform) by running Eclipse and then:
- from then menu Help select Install New Softare…
- next to Work with: open the drop down menu and select the update site of your Eclipse version
- select Web, XML, Java EE Development and OSGi Enterprise Development, press Next and complete the installation;
- to configure WTP to use Tomcat 7:
- select Windows -> Preferences -> Server -> Runtime Environments;
- press Add…;
- select “Apache Tomcat v7.0″;
- enter “/usr/share/tomcat7″ into the “Tomcat installation directory” field;
- press Ok;
- create a new “Dynamic Web Project”
- as Target Runtime select “Apache Tomcat v7.0″;
- press twice Next;
- select the “Generate the web.xml deployment descriptor” option at the final dialog;
- press Finish;
- open the Servers view:
- go to Window->Show View->Other…;
- choose the Servers under the Server category;
- click on new server wizard;
- choose Apache / Tomcat v7.0 Server and press Next;
- enter “/usr/share/tomcat7″ into the “Tomcat installation directory” field;
- press Next;
- select your project on the left pane under “Available” and press Add> to move it to the right pane under “Configured”;
- press Finish”;
- download the zip of Jersey;
- put the the jersey jars into the folder “WEB-INF/lib” and add them to the project build path;
- create your first RESTful Webservice by following this tutorial by Lars Vogel.
Your web services will be automatically deployed in the following folder:
~/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/
Your web service will be accessible through the following URI:
http://localhost:8080/UrlPattern/ClassPath/methodPath
Where:
- UrlPattern = the root of your service set inside the tag url-pattern in the web.xml;
- ClassPath = the path set for your class
- methodPath = the path set for your method
All the files you put in your WebContent folder will be accessible via http through the following URI:
http://localhost:8080/UrlPattern/yourfile
Note: make sure the tag url-pattern in the web.xml is set to something like this:
<url-pattern>/rest/*</url-pattern>
and not something like this:
<url-pattern>/*</url-pattern>
Troubleshooting
- to fix the error “Cannot create a server using the selected type” assign the tomcat7 group to your user. Assuming your username is pippo, run:
sudo adduser pippo tomcat7 cd ~/workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/ rm org.eclipse.jst.server.tomcat.core.prefs rm org.eclipse.wst.server.core.prefs
- to fix the error “Could not load the Tomcat server configuration at /usr/share/tomcat7/conf. The configuration may be corrupt or incomplete. /usr/share/tomcat7/conf/catalina.policy (No such file or directory)” assign the tomcat7 group to your user. Assuming your username is pippo, run:
sudo adduser pippo tomcat7
- to fix the error “Could not load the Tomcat server configuration at /Servers/Tomcat v7.0 Server at localhost-config. The configuration may be corrupt or incomplete” assign the tomcat7 group to your user. Assuming your username is pippo, run:
sudo adduser pippo tomcat7







thank you very much.. this was very useful!
am not getting the ‘server’ option at Windows -> Preferences -> Server -> Runtime Environments;
help me please
go to help->install new software->all available sites and install web option’s web tool in platform by selecting WST Server Adapters.( ull get in one minites)
Great, thanks, I used this to get Tomcat 7 working with Eclipse on Ubuntu 12.04 LTS, it worked perfectly.
Thank you for this great Guide. This is absolutely straightforward and it was easy to follow and repeat each step. It solved instantly my issues with connecting Eclipse to Tomcat using Ubuntu 12.04 LTS. In step 7 and 8 I got no errors, though I could not connect. After trying your terminal commands in step seven to eight it finally worked. Thanks again. =)
It was so helpfull & worked perfectly. thank you so much
Thanks a lot , but could you pleas eprovide, why do we need to set sudo chmod -R 777 /usr/share/tomcat7/conf for conf, is it security safety?
Awesome! I had trouble setting up tomcat7 in eclipse and your blog helped.
Thanx man, saved me alot of trouble
enter “/usr/share/tomcat7″ into the “Tomcat installation directory” field;
press Next;…after this i cant go with NEXT button…pls help me
I don’t understand what you mean with “I can’t go with NEXT button”. Please provide more details.
Log out and then log back in – worked for me.
thanks a lot!!worked perfect..
Reblogged this on Srikanth's Blog.
Thanks so much, solved all my problems this post.
You saved my day! I was going crazy. Thank you very much!
Very good friend, after much work I found a post with a solution to my problems!
Thanks so much!! This helped me loads as I’m new to lynux and learning as I go
Thanks a lot! I spent an hour trying to configure the server on Eclipse. Your link approach worked. Cheers.
Thank you very much!
THANKS A LOT! Amazing tutorial!
thanks buddy,keep it up!!
This helped me a lot!!Thanks a lot!!!
thank you so much
This error keeps popping up each time I try to start the server from Eclipse: “Could not load the Tomcat server configura… …tion may be corrupt or incomplete”. I copied /etc/tomcat7 contents into the Eclipse’s Server’s configuration directory (the one usually in ~/workspace/Servers/Tomcat v7.0…..) and I make myself owner of /etc/tomcat7 and /usr/share/tomcat7 recursively. What am I missing? Thanks
I have updated the tutorial, try to follow it from the beginning and then let me know.
Hey, I am still getting the “Could not load the Tomcat server configuration at /usr/share/tomcat7/conf. The configuration may be corrupt or incomplete.
/usr/share/tomcat7/conf/catalina.policy (No such file or directory)” problem when I start the new server wizard. I have added my username to the tomcat7 group. Any thoughts?
Hi,
some additionnal troubleshooting fixes can be found at http://directjump2java.blogspot.fr/2012/08/tomcat-7-and-eclipse-integration.html . Mainly deals with incomplete configuration of tomcat7 in Ubuntu (symlinks and chmod stuffs).
Hi, All the steps worked except the “press Finish” ]on step 9… Bummer. I’ve tried all the little steps suggested as a fix to it. Still fails