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

  1. Install Eclipse and Tomcat 7 by running in a terminal:
    sudo apt-get install eclipse tomcat7 -y
  2. 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.

  3. stop the system-wide Tomcat by running:
    /usr/share/tomcat7/bin/shutdown.sh
  4. prevent the system-wide Tomcat from automatically starting at boot by running:
    sudo update-rc.d tomcat7 disable
  5. install WTP (Web Tools Platform) by running Eclipse and then:
    1. from then menu Help select Install New Softare…
    2. next to Work with: open the drop down menu and select the update site of your Eclipse version
    3. select Web, XML, Java EE Development and OSGi Enterprise Development, press Next and complete the installation;
  6. to configure WTP to use Tomcat 7:
    1. select Windows -> Preferences -> Server -> Runtime Environments;
    2. press Add…;
    3. select “Apache Tomcat v7.0″;
    4. enter “/usr/share/tomcat7″ into the “Tomcat installation directory” field;
    5. press Ok;
  7. 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;
  8. open the Servers view:
    • go to Window->Show View->Other…;
    • choose the Servers under the Server category;
  9. 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”;
  10. download the zip of Jersey;
  11. put the the jersey jars into the folder “WEB-INF/lib” and add them to the project build path;
  12. 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:

  1. UrlPattern = the root of your service set inside the tag url-pattern in the web.xml;
  2. ClassPath = the path set for your class
  3. 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
About these ads
Categories: HowTos, Ubuntu
  1. Vale
    08 Jun 2012 at 3:29 pm | #1

    thank you very much.. this was very useful!

  2. suresh dharavath
    02 Jul 2012 at 8:32 pm | #2

    am not getting the ‘server’ option at Windows -> Preferences -> Server -> Runtime Environments;
    help me please

    • Suraj
      12 Aug 2012 at 4:12 am | #3

      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)

  3. 07 Jul 2012 at 4:31 pm | #4

    Great, thanks, I used this to get Tomcat 7 working with Eclipse on Ubuntu 12.04 LTS, it worked perfectly.

  4. semodesign
    19 Jul 2012 at 8:47 am | #5

    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. =)

  5. prakash
    25 Jul 2012 at 12:11 pm | #6

    It was so helpfull & worked perfectly. thank you so much

  6. Dzmitry
    14 Aug 2012 at 10:08 pm | #7

    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?

  7. wb
    18 Aug 2012 at 9:49 am | #8

    Awesome! I had trouble setting up tomcat7 in eclipse and your blog helped.

  8. leon
    03 Sep 2012 at 12:43 pm | #9

    Thanx man, saved me alot of trouble

  9. 25 Sep 2012 at 12:19 pm | #10

    enter “/usr/share/tomcat7″ into the “Tomcat installation directory” field;
    press Next;…after this i cant go with NEXT button…pls help me

    • 25 Sep 2012 at 12:32 pm | #11

      I don’t understand what you mean with “I can’t go with NEXT button”. Please provide more details.

    • 29 Nov 2012 at 1:44 am | #12

      Log out and then log back in – worked for me.

  10. gamer
    27 Sep 2012 at 6:40 am | #13

    thanks a lot!!worked perfect..

  11. srikanth ganta
    29 Sep 2012 at 6:40 pm | #14

    Reblogged this on Srikanth's Blog.

  12. Abdo
    11 Oct 2012 at 10:32 am | #15

    Thanks so much, solved all my problems this post.

  13. 15 Oct 2012 at 2:32 pm | #16

    You saved my day! I was going crazy. Thank you very much!

  14. João Batista Ladchuk
    21 Nov 2012 at 2:14 am | #17

    Very good friend, after much work I found a post with a solution to my problems!

  15. Tom
    21 Nov 2012 at 8:24 pm | #18

    Thanks so much!! This helped me loads as I’m new to lynux and learning as I go :-)

  16. _mfierro
    05 Dec 2012 at 5:26 am | #19

    Thanks a lot! I spent an hour trying to configure the server on Eclipse. Your link approach worked. Cheers.

  17. Szabolcs
    12 Dec 2012 at 3:56 pm | #20

    Thank you very much!

  18. 15 Jan 2013 at 9:59 pm | #21

    THANKS A LOT! Amazing tutorial!

  19. ashok
    24 Jan 2013 at 5:28 pm | #22

    thanks buddy,keep it up!!

  20. 05 Feb 2013 at 3:55 pm | #23

    This helped me a lot!!Thanks a lot!!!

  21. dan
    15 Mar 2013 at 10:05 am | #24

    thank you so much

  22. 15 Mar 2013 at 5:08 pm | #25

    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

    • 19 Mar 2013 at 6:10 pm | #26

      I have updated the tutorial, try to follow it from the beginning and then let me know.

  23. joe
    29 Mar 2013 at 10:35 pm | #27

    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?

  24. 16 May 2013 at 3:17 pm | #29

    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 :-(

  1. 12 Sep 2012 at 10:05 pm | #1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: