Setting Up and Integrating Tomcat into Eclipse

Steps to Setting Up Tomcat on windofkeltia

Copy the following to /tmp:

apache-tomcat-6.0.16.tar.gz (from tomcat.apache.org) jdk-6u3-linux-i586.bin (from java.sun.com)

Update to JDK 6:
chmod +x /tmp/jdk-6u3-linux-i586.bin - to make the binary executable
cd /usr/lib/jvm                      - the destination directory
/tmp/jdk-6u3-linux-i586.bin          - execute the binary installer
ln -s jdk1.6.0_03/ java              - create a link, 'java' to the new JDK directory

Technically, this is all that is required on SuSE. The script '/etc/profile.d/alljava.sh' will set the JAVA_HOME, etc. env variables when someone logs in. However, I like to add it to the path, so I create /etc/bash.bashrc.local and add it to the path:

export PATH=$JAVA_HOME/bin:$PATH

You must log out and back in to pick the change up.

Validate:

java -version

should come back with:

java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

JDK 6 is ready. Now for Tomcat:

cd /usr/share                             - the destination directory
tar xvfz /tmp/apache-tomcat-6.0.16.tar.gz - extract the tarball
ln -s apache-tomcat-6.0.16/ tomcat        - create link: /usr/share/tomcat
cd /usr/share/tomcat/bin                  - move to tomcat's bin directory
tar xvfz jsvc.tar.gz                      - extract the source tarball for jsvc
cd jsvc-src/                              - move into the directory
chmod +x configure                        - make configure executable
./configure
make
cp jsvc ..                                - copy jsvc up into the bin directory

jsvc is the launching program for Tomcat

Create /etc/profile.d/tomcat.sh with the following content:

export CATALINA_HOME=/usr/share/tomcat
export CATALINA_BASE=$CATALINA_HOME

This will set the environment vars when a user logs in.

There is a script in /usr/share/tomcat/bin/jsvc-src/native, Tomcat5.sh that you can modify and copy to the /etc/init.d/ directory to start Tomcat. I have copied over my own modified script: /etc/init.d/tomcat. You can get it for other SuSE systems from that directory or from /tmp.

ln -s /etc/init.d/tomcat /usr/sbin/rctomcat - create a link to the script in /usr/sbin
chmod +x /etc/init.d/tomcat                 - make the script executable

Create a system-level group and user for tomcat:

yast

In Security and Users, Group Management:

Set Filter (alt-s) and select System Groups.
Add group (alt-a): name: tomcat, Members: rbateman, sfranson
Accept (alt-a)
Change to users (alt-u), Set Filter (alt-s): select System Users
Add user (alt-a): Name: Tomcat User; username: tomcat; password: tomcat
Disable user Login (alt-i)
Details (alt-d) (accept warnings about password)
Set Home Directory (alt-h) to /usr/share/tomcat
Set Default Group (alt-f) to tomcat
Clear other group memberships (alt-o)
Accept (alt-a)
Finish (alt-f)
Quit (alt-q)
cd /usr/share
chown -R tomcat:tomcat apache-tomcat-6.0.16/ - change user:group ownership to tomcat:tomcat

rctomcat start                               - start Tomcat

That is the basics. If tomcat is running you can verify using port 8080.

I verified it via:

cd /tmp
mkdir tomcat.test
cd tomcat.test
wget localhost:8080

It should have retrieved index.html

Apache integration coming in part 2! :D

Part Two: To Setup Simple Reverse Proxy to Tomcat

cd /etc/apache2/vhosts.d
cp _windofkeltia.conf _windofkeltia.srf.orig    - save in case I mess up

Add the following to _windofkeltia.conf:

    ProxyRequests Off
    
        Order deny,allow
        Allow from all
    
    ProxyPass /tomcat/ http://localhost:8080/
    ProxyPassReverse /tomcat/ http://localhost:8080/

The first five lines are for security, they are necessary to indicate to Apache that we are running a reverse proxy and not a normal proxy. Important! If you want to proxy from other v-hosts, be sure to add these lines.

The ProxyPass indicates that everything that goes to http://www.windofkeltia.com/tomcat/... will be passed to Tomcat, but appear to Tomcat as if the "/tomcat/" path was not there. The ProxyPassReverse fixes URL's and paths coming out of Tomcat to add the "/tomcat/" back in.

Now, to add the proxy modules to Apache:

yast
System, /etc/sysconfig Editor
Network, WWW, Apache2, APACHE_MODULES
Add 'proxy' and 'proxy_http' modules

These modules should be installed by default with Apache in /usr/lib/apache2.

rcapache2 restart         - restart apache

Test: http://www.windofkeltia.com/tomcat/

Voila! You're tomcat is served!

Controlling Tomcat on Windows

Russ at home says:

I'm not getting class files out of Eclipse for classes that do not demonstrate errors. How do I instruct Eclipse to do what the javac -d option would do?

Satori says:

The Package Explorer view will not show .class files.

Satori says:

You may see them under the Navigation view, but why?

Russ at home says:

Ah. I thought I had seen some in my other projects (HFDP and DVD catalog).

Russ at home says:

I have to copy them out to special paths for Tomcat to see.

Russ at home says:

But I don't know where they are in Eclipse.

Russ at home says:

I mean, they're on the path /bin/com/example/web|model, but I don't actually see that in the GUI.

Satori says:

Go to Window, Show View and find Navigator.

Russ at home says:

Yeah, I had done that.

Russ at home says:

I guess I'm just going to have to roll with the punches until I've done the book, then I can move into the modern world?

Satori says:

With Navigator you can browse to the classes directory under your project and select the files/directory from there and paste it into whatever path you want via the normal file explorer.

Russ at home says:

Sure, I can see that.

Satori says:

*copy and paste

Russ at home says:

In the modern world, will Eclipse be helping do this in some clean fashion?

Russ at home says:

Actually, Eclipse is click and draggable to the File Explorer. It's cool.

Satori says:

You can associate a Tomcat installation with Eclipse and Eclipse will keep the two directories in sync.

Russ at home says:

Alright--something to look forward to.

Russ at home says:

In the meantime, do you know what constitutes restarting Tomcat on Windows? I'm supposed to restart it according to the book so it will recognize new stuff I put out, but there's no Tomcat "process" anywhere I can find to bounce.

Russ at home says:

It just automagically worked after I launched Firefox and typed in http://localhost:8080/.

Satori says:

If you've installed tomcat as a service, you can restart it via the Services control panel thing.

Russ at home says:

Hmmm. I don't even know, I just used what they gave me for Windows.

Russ at home says:

Ah, I found it: Control Panel->Administrative Tools->Services->Apache Tomcat->Stop (or Restart).

Russ at home says:

Almost like an /etc/init.d thingey.

Satori says:

Almost.

Tomcat Start-up Script on Linux

See tomcat.sh.

Russell Bateman says:

As I modify the /etc/init.d/tomcat.sh script, I don't have the foresight to modify the DAEMON_HOME and TOMCAT_USER definitions.

Russell Bateman says:

I guess I need to go looking for the Tomcat daemon?

Russell Bateman says:

No, this appears to be some magic, but everyday username.

Russell Bateman says:

I can't put DAEMON_HOME at "$CATALINA_HOME/bin" because it needs to be a directory above an existing path src/native/unix/jsvc.

sfranson@gmail.com says:

The instructions I sent for setting up content explain the generation of the DAEMON_HOME (jsvc) and the system account that tomcat runs under, TOMCAT_USER (tomcat).

sfranson@gmail.com says:

*settup up tomcat

sfranson@gmail.com says:

*setting up, even

sfranson@gmail.com says:

Russell Bateman says:

Okay. I just encountered the /etc/init.d/tomcat.sh script bit in your write-up before those other things and I was doing it sequentially. I'll push an indirection on the stack and move on (which is what I was doing).

Russell Bateman says:

Hmmm... you have me adding a group named tomcat, but I cannot seeing as there is already a user by that name (and I didn't set it up).

Russell Bateman says:

I'm loathe to delete the user for fear the daemon needs to run as it or something important like that.

Russell Bateman says:

I wonder how my installation here can be so different from the one at home. I guess it's because I upgraded from 10.1 rather than set it up from scratch as I did at home.

sfranson@gmail.com says:

Have you tried installing tomcat via yast before?

Russell Bateman says:

Hmmm... your instruction show a tomcat user and a group.

Russell Bateman says:

No, it is offered, but is not presently installed according to graphical Yast.

Russell Bateman says:

I assumed it is way old since the JDK offered by Yast is 1.5.

sfranson@gmail.com says:

If the tomcat user and group already exist then that is fine.

Russell Bateman says:

Well, the user does. I'll have to check for the group.

Russell Bateman says:

Yup. Both exist. I'll just put myself into the group.

Russell Bateman says:

I've arrived at the end of the e-mailed instructions. There is no /usr/sbin/rctomcat to start and, anyway, my /etc/init.d/tomcat.sh script is still wrong. I stumbled upon nothing that said what DAEMON_HOME and TOMCAT_USER should be.

Russell Bateman says:

Now, I know that TOMCAT_USER should probably be "tomcat" if I want the daemon to run as that. But, "russ" is also a member of group "tomcat."

sfranson@gmail.com says:

Yes. So that you can write to the /usr/share/tomcat/webapps directory, to which you should allow group write rights

Russell Bateman says:

Ah, okay. But the start/stop script has nothing to do with that.

sfranson@gmail.com says:

Indeed, on the webapps directory I set the 'sticky' bit too, to keep all entries in the directory the same group.

sfranson@gmail.com says:

No. Hold on I have to bounce...

sfranson@gmail.com says:

Messenger is freeking out.

Russell Bateman says:

I recopied the instructions to you with the few that I can't implement explained.

Russell Bateman says:

To your scott.r.franson@gmail.com

sfranson@gmail.com says:

Hold on I have to bounce...

Some good links for setting up Tomcat...

Basic Skill in Web Application: Tomcat Directory Structure

To create a web application, go to /usr/share/tomcat/webapps and create a subdirectory corresponding to your app: myapp Underneath, create WEB-INF into which the web.xml will go. Other directories as dictated by the app including class files under classes/long-package-path/*.class, etc.

Tutorial Links

My first JSP:

Questions

What is the ROOT directory under /usr/share/tomcat/webapps?

The ROOT webapp is for the "root" of tomcat: http://www.windofkeltia.com/tomcat/ as opposed to http://www.windofkeltia.com/tomcat/poop/

Starting the Tomcat Server from Eclipse

sfranson@gmail.com says:

Are you logged in as root or another user?

Russell Bateman says:

I was trying to log in as root as a last resort, but, oddly enough, I cannot launch eclipse as root!!!!!!

Russell Bateman says:

So, no, I'm logged in as russ and tomcat is one of my groups.

sfranson@gmail.com says:

/usr/sbin is only in the path of the root user. And you can't start/stop tomcat anyway unless you are root.

sfranson@gmail.com says:

/usr/sbin is where rctomcat lives.

Russell Bateman says:

I thought I had broken Tomcat for a while this afternoon. I have it up.

Russell Bateman says:

Boy, I did a global find for that file and it never found it.

Russell Bateman says:

Anyway, /etc/init.d/tomcat works. Should I not use it?

Russell Bateman says:

Using that script is a no-brainer since I'm used to doing that--our daemons all use that method.

Russell Bateman says:

So, the error message (in case this dings any bell at all in your head) states "Could not load the Tomcat server configuration at /Servers/Tomcat v6.0 Server at localhost-config. The configuration may be corrupt or incomplete. This is repeated 4 times in the detail.

Russell Bateman says:

That path seems pretty odd and un-Linux-like.

sfranson@gmail.com says:

It is in reference to Eclipse

Russell Bateman says:

Ok.

sfranson@gmail.com says:

Meaning it created a "project" called "Servers"

Russell Bateman says:

There was an error statement vaguely similar to that last night which I fixed by making conf/catalina.policy executable.

Russell Bateman says:

I'm just brick-walled here until someone at JavaRanch can answer. I posted a reply to another guy who had exactly the same problem except that he was getting much further.

Russell Bateman says:

And, needless to say, I have looked all over the (freakin') web.

sfranson@gmail.com says:

The tomcat that you installed in /usr/share/tomcat was inteded as a server process. You can stop that one (rctomcat stop) and extract another installation of tomcat in your user directory for eclipse to use for development.

Russell Bateman says:

And found two or three people with the same or nearly same problem.

sfranson@gmail.com says:

Eclipse will not be able to do anything with the one installed in /usr/share/tomcat

sfranson@gmail.com says:

Just create another one in your user directory with you as the owner.

Russell Bateman says:

Yeah, that resembles an answer I read. I did stop Tomcat, but the rest of it--actually doing Java code to awaken Tomcat, is beyond me.

Russell Bateman says:

Ah.

Russell Bateman says:

So, you are saying to copy the entire /usr/share/tomcat tree into /home/russ, fix all permissions, ownership, etc. and give it another try?

Russell Bateman says:

That's a good idea. I'll try it immediately.

sfranson@gmail.com says:

NO! Just extract the Tomcat tar ball into your user directory.

Russell Bateman says:

Okay. I've done that. There's a link named /home/russ/tomcat to /home/russ/apache-tomcat-6.0.16.

Russell Bateman says:

I'll delete my server out of Eclipse and try to recreate it.

Russell Bateman says:

I'm having trouble pulling this off: it's not giving me the opportunity to browse or otherwise name the path to my Tomcat server.

Russell Bateman says:

Ah, I had to delete ALL knowledge of Tomcat from the Eclipse server list.

Russell Bateman says:

Okay, I had to stop the normal Tomcat.

Russell Bateman says:

Now, I successfully started it, but I got a list of nasty errors terminating in the list you see at http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=56&t=006237

Russell Bateman says:

However, I think my own errors in red are more significant.

sfranson@gmail.com says:

java.lang.ClassNotFoundException: org.apache.catalina.Container?

Russell Bateman says:

I've copied and sent the list to scott.r.franson@gmail.com.


Feb 26, 2008 6:05:07 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:WTP-Tutorial-I' did not find a matching property.
Feb 26, 2008 6:05:07 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-1.5.0-sun-1.5.0_update12/jre/lib/i386/client:/usr/lib/jvm/java-1.5.0-sun-1.5.0_update12/jre/lib/i386:/usr/lib/jvm/java-1.5.0-sun-1.5.0_update12/jre/../lib/i386:/usr/lib/jvm/jdk1.6.0_04/jre/lib/i386/client::/usr/lib/jvm/jdk1.6.0_04/jre/lib/i386::/usr/lib/xulrunner-1.8.1b2:/usr/lib/xulrunner-1.8.1b2
Feb 26, 2008 6:05:08 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Feb 26, 2008 6:05:08 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1649 ms
Feb 26, 2008 6:05:08 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Feb 26, 2008 6:05:08 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.16
Feb 26, 2008 6:05:08 PM org.apache.tomcat.util.modeler.Registry registerComponent
SEVERE: Null component Catalina:type=JspMonitor,name=jsp,WebModule=//localhost/WTP-Tutorial-I,J2EEApplication=none,J2EEServer=none

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.UnsupportedClassVersionError: Bad version number in .class file
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1819)
        at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:872)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1327)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
        at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:108)
        at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:58)
        at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:297)
        at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1064)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4252)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:516)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
        ... 6 more


Russell Bateman says:

The "severe" error is "Null component Catalina: type=jspMonitor,name=jsp, WebModule=//localhost/WTP-Tutorial-I,J2EEApplication=none,J2EEServer=none

Russell Bateman says:

Then it goes on to do the class list.

Russell Bateman says:

I'm following a tutorial exactly in every sense.

Russell Bateman says:

It's named WTP-Tutorial-I--the project name it uses.

sfranson@gmail.com says:

You are starting Tomcat with the 1.5 JRE. You need to get Eclipse to recognize your 1.6 JRE installation and point the configuration for Tomcat to use that.

Russell Bateman says:

Ah. It's like I have to do that every time despite importing my preferences.

Russell Bateman says:

I'll go find out where that setting is. It takes me a minute, I know.

Russell Bateman says:

Okay, I'm in Java Build Path preferences and I see under libraries that I'm using JRE System Library [java-1.5.0-sun-1.5.0_update12].

Russell Bateman says:

Is that what must be deleted and re-added?

Russell Bateman says:

And, where is Java 6 going to be on my disk?

Russell Bateman says:

Okay, under /usr/lib/jvm, I don't have a JRE for Java 6, but I have a JDK (jdk1.6.0_04).

Russell Bateman says:

I read somewhere that the JDK is "better" than the JRE because it has the SDK plus a JRE anyway.

sfranson@gmail.com says:

Right.

Russell Bateman says:

So, I don't know what (if not the JRE System Library) to delete nor what (exactly, by filename) to add.

Russell Bateman says:

I've looked under /usr/lib/jvm/jdk1.6.0_04 and don't see anything "addable." Even under the lib subdirectory.

sfranson@gmail.com says:

Just select the jdk1.6.0... directory

sfranson@gmail.com says:

Eclipse should recognize it.

Russell Bateman says:

Yeah, there are myriad files under the jdk 6.0 directory.

Russell Bateman says:

Yeah, but I have to navigate hundreds of directories before finding something Eclipse "recognizes." I've been doing just that...

Russell Bateman says:

Is it a .jar file I'm looking for?

Russell Bateman says:

I've looked under the jre and lib subdirectories. Deeply under the jre one which goes way deep.

sfranson@gmail.com says:

No. At least with the windows version of Eclipse, you can browse for the "JRE home directory." Just select the jdk1.6.0.... directory.

Russell Bateman says:

I'll give that a try.

Russell Bateman says:

Nope, it just opens the directory in the file browser.

Russell Bateman says:

Hang on. I've analyzed the one I haven't removed yet and it gives me an idea.

sfranson@gmail.com says:

You are in Window, Preferences, Java, Installed JREs, Add JRE?

Russell Bateman says:

No, I was under the project preferences, Java Build Path stuff.

Russell Bateman says:

Hmmm... It wants me to name the JRE.

Russell Bateman says:

Nope, I had it wrong.

Russell Bateman says:

I had to add /usr/lib/jvm/jdk1.6.0_04/jre and it named itself which I take as "Eclipse recognizing" it.

Russell Bateman says:

Okay, now it may be working. I'm getting the same question as the one I responded to: INFO: Server startup in 850 ms

Russell Bateman says:

I guess that means it's up.

Russell Bateman says:

This is further than I got in the tutorial, so I don't know what the next step is. Thanks for suffering Linux this evening.

Russell Bateman says:

I'll pick the tutorial back up where I had failed.