*
The moose likes IDEs, Version Control and other tools and the fly likes Eclipse + Servlet + Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Eclipse + Servlet + Tomcat" Watch "Eclipse + Servlet + Tomcat" New topic
Author

Eclipse + Servlet + Tomcat

meimei li
Greenhorn

Joined: May 19, 2003
Posts: 24
Hi, I am new to Eclipse and I am trying to compile servlets in Eclipse and to automatically deploy it to Tomcat. I encountered following 3 questions. Can anybody help?

1. How to compile Servlets in Eclipse? If I click "Run", I was required to choose a configuration from Java Applet to Eclipse Application. It seems not what I am looking for.

2. I downloaded the " Sysdeo Eclipse Tomcat Launcher plugin" for Eclipse 3.1, and have installed Tomcat 4.1.31. Set up Environment variables like "CATALINA_HOME" and "TOMCAT_HOME". However, after I open Java Perspective, go to Windows->Custom Perspective-> commands, I couldn't find "Available Command Groups", and therefore I can't enable "Tomcat" plug in. What's wrong?

3. How to make Eclipse automatically put the compiled classes into $TOMCAT_HOME/webapps/APPLICATION/WEB-INF/classes directory. I tried
project->preference->Java Build Path->Order and Export. But the default output directory must be a location beneath the project.

Your input will be greatly appreciated.


SCJP
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

MeiMei,
1) You compile a servlet the same way as any other Java class. (Project -->
Rebuild or have Eclipse set to automatically recompile.) Just make sure you have j2ee.jar or servlets.jar in your classpath.

2) I don't know this one. Let's wait for someone who has used this plugin.

3) You can't compile to an external directory as you've noticed. You can manually copy the files or write an Ant file to do it automatically.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

You need to RTFM sysdeo's installation instructions. When properly installed, you don't have to switch on anything. Just restart eclipse and the Tomcat icons appear on the toolbar (along with the Tomcat menu). The only fancy stuff you'd need is if you had existing webapp source you wanted to make available to be debugged, in which case you go to the Window/Preferences->Tomcat property editor.

You could build into TOMCAT_HOME/webapps/your_app_name directory, but I really don't recommend it. I keep a build/webapp directory in my project where I assemble everything (set the output class directory to build/webapp/WEB-INF-classes). Then I create a TOMCAT_HOME/conf/Catalina/localhost/your_app_name.xml file that defines the <Context> for that webapp. Which is the recommended way to do such things in Tomcat5. Editing server.xml and/or stuffing things in TOMCAT_HOME/webapps isn't really recommended. Especially editing server.xml.

Caveat: Tomcat 4 had the option of taking a WAR dropped into TOMCAT_HOME/webapps and exploding it. If the packages WAR was older than the exloded WAR files, nothing would be done. In Tomcat5, apparently all WARs are exploded, but they don't seem to be checking the relative ages (at least in Tomcat 5.0.28), so you have to manually remove the exploded WAR to get the updated stuff.


Customer surveys are for companies who didn't pay proper attention to begin with.
meimei li
Greenhorn

Joined: May 19, 2003
Posts: 24
Thanks very much for all your kind replies.

To compile the servlet, I did go to "project->build all" to build the project, but I didn't see the class file in the output "classes" directory. Currently, in the "Java BuildPath" dialog, the default output folder is set to PROJECT_NAME/classes. And here are the files under the project "HelloWorld" and the content in the ".classpath" file that resides under the project directory.

D:/eclipse/workspace1/HelloWorld>ls -a
. .classpath HelloWorldServlet.java
.. .project classes

D:/eclipse/workspace1/HelloWorld>cat .classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER
"/>
<classpathentry kind="lib" path="D:/jakarta-tomcat-4.1.31/common/lib/ser
vlet.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>

I can't understand what has went wrong. I tried "project->build automatically" option, and I didn't see the class file generated either.

Your suggestion will be greatly appreciated.

[edited to escape XML <]
[ June 20, 2006: Message edited by: Jeanne Boyarsky ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

MeiMei,
Take a look in the resource perspective. Not all files show up in the Java perspective. Class files are in that category so it is possible that they are there, but you just don't see them.
meimei li
Greenhorn

Joined: May 19, 2003
Posts: 24
Thanks for your help. Now I did get servlets automatically compiled in Eclipse, but still having trouble integrating the Tomcat plugin with Eclipse.

After I downloaded and unzipped the "Sysdeo Eclipse Tomcat Launcher plugin" into my Eclipse/plugin directory, I did see "com.sysdeo.eclipse.tomcat_3.1.0" exisiting in the plugin directory. However, there is no "tomcat" icon appearing in the toolbar, neither a "Tomcat" list under "Window->prefernce->customer perspective...->commands->Available command groups". Actually, I can't find "Avaiable command groups" in "comands" dialog.

Your help will be greatly appreciated.
meimei li
Greenhorn

Joined: May 19, 2003
Posts: 24
To correct an error in my previous reply, I can't find "Available command groups" under "Window->customer perspective...->commands" instead of "Window->prefernce->customer perspective...->commands->Available command groups".
 
Consider Paul's rocket mass heater.
 
subject: Eclipse + Servlet + Tomcat
 
Similar Threads
servlet/jsp not running in tomcat
[SOLVED] Oracle OCI library already loaded in another classloader exception
jars vs. files
complex source directories in Eclipse Projects?
struts-blank.war