Install Tomcat with Eclipse

Howto install Tomcat with Eclipse IDE on MacOS X.

What we need:

Tomcat

Eclipse JEE

1. Extract Eclipse into your Applicationfolder and Tomcat to your prefered location for example into your home directory.

2. change into the apache-tomcat-6.0.20/bin directory and make all .sh files executeable

cd <pathtoyourtomcat>/apache-tomcat-6.0.20/bin
chmod +x *.sh

3. test if it starts

./setclasspath.sh
./startup.sh

something like this should appear:

./startup.sh
Using CATALINA_BASE:   apache-tomcat-6.0.20
Using CATALINA_HOME:   apache-tomcat-6.0.20
Using CATALINA_TMPDIR: apache-tomcat-6.0.20/temp
Using JRE_HOME:       /System/Library/Frameworks/JavaVM.framework/Home

4. Test you tomcat installation via your Browser

http://localhost:8080/

if everything works like expected shut the tomcat instance down

./shutdown.sh

5. Now we add Tomcat to our Eclipse environment

Double click on the server and select “Use Tomcat installation (take control of Tomcat installation)”:

Set tomcat preference to use installation directory parameters

Set tomcat preference to use installation directory parameters

 

6. Modify the tomcat-users.xml file located in /<pathtotomcat>/apache-tomcat-6.0.20/conf directory and add:

<role rolename=”admin”/>
<role rolename=”manager”/>
<user username=”user” password=”password” roles=”admin,manager”/>

with your username and password for administration.

This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

23 thoughts on “Install Tomcat with Eclipse

  1. David

    Thank you for the tutorial, I was wondering if you knew why when I am trying to find out why when I install Tomcat 6 or 7, and Eclipse EE (Helios) on my OS X 10.6 nothing seems to happen. Tomcat starts just fine from the command line. But in Eclipse, the server appears to start but in fact hitting the url gives me a Apache 404. Here is some of the console log:
    INFO: Starting service Catalina
    May 4, 2011 8:57:12 PM org.apache.catalina.core.StandardEngine startInternal
    INFO: Starting Servlet Engine: Apache Tomcat/7.0.12
    May 4, 2011 8:57:12 PM org.apache.coyote.AbstractProtocolHandler start
    INFO: Starting ProtocolHandler [\"http-bio-8080\"]
    May 4, 2011 8:57:12 PM org.apache.coyote.AbstractProtocolHandler start
    INFO: Starting ProtocolHandler [\"ajp-bio-8009\"]
    May 4, 2011 8:57:12 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 280 ms

    Reply
  2. Raymond

    @David,
    I have the exact same problem! So frustrating. Have you figured any thing out?? Can’t seem to find any solutions!

    Reply
    1. Banym Post author

      I can reproduce the issue. It looks like it’s because of the different location parameters used by Eclipse to start the tomcat instance. Did you try to deploy a web application from you Eclipse?

      Reply
  3. Pingback: Dynamic Web Project mit Eclipse aufsetzen « FunThomas Blog (de)

    1. Banym Post author

      Go to server tab and double click on your tomcat server configuration and select: “Use Tomcat installation (take control of Tomcat installation)”

      I updated the tutorial you should see it in a screenshot above.

      Regards,

      Dominik

      Reply
  4. Adam

    Thank you SO much for pointing out the “Use Tomcat installation (take control of Tomcat installation)” setting! I was going crazy with this. Now I can truly control Tomcat and deploy properly from within Eclipse.

    Reply
  5. noemail@gmail.com

    Thank you! I was receiving “could not load the Tomcat server configuration at /Servers/Tomcat v7.0 Server at localhost-config.” until I deleted my tomcat server and used your setup.

    Reply
  6. peter steiner

    “Go to server tab and double click on your tomcat server configuration and select: “Use Tomcat installation (take control of Tomcat installation)”
    I updated the tutorial you should see it in a screenshot above.
    Regards,
    Dominik”

    Thanks, saved me some time and confusion! Only screener I can wee in the tutorial though!

    I deleted server and created a new one, then I could change the server locations property.
    /Peter

    Reply
  7. Vitalii

    Hi!
    I’m new to Mac OS and need to use one of IDE with tomcat to create some servlets. I’ve installed Eclipse for EE Developers and tomcat 6.0.33 and have problems with this:

    ./setclasspath.sh

    The BASEDIR environment variable is not defined
    This environment variable is needed to run this program

    what does it mean and what should I do, explain me please.
    Thanx a lot!

    Reply
    1. Banym Post author

      Hi Vitalli,

      how do you want to use the tomcat? Do you want to run it out of your IDE and deploy your servlets directly to it?

      When did you get this message? When you run the script by your own?

      Regards,

      Dominik

      Reply
  8. Kirsty

    @Vitalii and @Banym,

    I am having the same issue on Mac OSX.
    I want to run tomcat through Eclipse using JEE. I’m fairly new to servlets/tomcat so don’t really know how else to explain. When I try to view localhost:8080 in the browser (after typing what Vitalii wrote and getting the same message, and then typing ./startup.sh and getting

    “Using CATALINA_BASE: /Users/kirsty/Documents/apache-tomcat-6.0.33
    Using CATALINA_HOME: /Users/kirsty/Documents/apache-tomcat-6.0.33
    Using CATALINA_TMPDIR: /Users/kirsty/Documents/apache-tomcat-6.0.33/temp
    Using JRE_HOME: /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
    Using CLASSPATH: /Users/kirsty/Documents/apache-tomcat-6.0.33/bin/bootstrap.jar
    touch: /Users/kirsty/Documents/apache-tomcat-6.0.33/logs/catalina.out: No such file or directory
    /Users/kirsty/Documents/apache-tomcat-6.0.33/bin/catalina.sh: line 375: /Users/kirsty/Documents/apache-tomcat-6.0.33/logs/catalina.out: No such file or directory”)

    I am not seeing anything but an error message in my browser.

    Reply
    1. Banym Post author

      First you should try to get an working tomcat on you machine. Try to download the latest version you want to use and run it via the startup.sh script from a terminal.
      For me there is a line in you post you should have a closer look: touch: /Users/kirsty/Documents/apache-tomcat-6.0.33/logs/catalina.out: No such file or directory
      The startup procedure should create this file. Are you allowed to write in this folder?

      And after your tomcat is working from a terminal you should make the connection between your IDE and the tomcat server.
      Regards,

      Dominik

      Reply
  9. David

    I also ran into the BASEDIR problem Vitalli did. I’m using 6.0.33 on OS X Lion (10.7.2). If you look at the content of setclasspth.sh it appears to use BASEDIR to construct paths relative to your Tomcat install directory, for the script checks a path to itself…

    if [ ! -x "$BASEDIR"/bin/setclasspath.sh ]; then

    To work around the issue, I simply set BASEPATH to my tomcat directory before running the other two steps. I put Tomcat in my home directory so I did this:

    export BASEDIR=”/Users/my_user_name/apache-tomcat-6.0.33″

    Then ran the setclasspath.sh and startup.sh scripts. It worked.

    Following the rest of the instructions, I’m also able to start and stop the server with Eclipse.

    But, I do get a 404 when visiting http://localhost:8080/ when I start the sever with Eclipse. I think this is normal. When I hit a URL for a web app I’m working on in Eclipse, ex: http://localhost:8080/MyBasicWebApp/ it works.

    Thank you Banym for these excellent instructions!

    Cheers,
    David

    Reply
  10. Sanjee

    I followed strictly above and able to configure tomcat in my eclipse and working fine ,but multiple time i made changes my java class then server will crashed and some times it will be out memory permgent exception,how I will resolve these issues.
    Please assist me asap.

    Reply
    1. Banym Post author

      Hello Sanjee,

      check your max memory values you are using for your java, eclise and tomcat. There you can increase the max memory. If you change your classes you maybe need to redeploy your application that’s maybe the cause of the crash if you have tomcat up and running while you’re changing the code.

      Regards,
      Dominik

      Reply
  11. Pingback: Frameworking : Infozaic

  12. Jim Geldemrann

    Please add to the – Double click on the server and select “Use Tomcat installation (take control of Tomcat installation)”:

    “Set deploy path to the default value (current set)” – If the Tomcat main screen does not appear that this path will need to be set to theTomcat’s web apps folder.

    Reply
  13. David Wolf

    For an existing Tomcat application it was necessary for me to copy the CATALINA_OPTS and JAVA_OPTS from $CATALINA_HOME/conf/setenv.sh into the VM arguments (Open Launch Configuration > Arguments).

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>