Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eclipse + Servlet + Tomcat

 
meimei li
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17987
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
meimei li
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic