my dog learned polymorphism*
The moose likes IDEs, Version Control and other tools and the fly likes Setting up Tomcat/Web project in Eclipse 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 "Setting up Tomcat/Web project in Eclipse" Watch "Setting up Tomcat/Web project in Eclipse" New topic
Author

Setting up Tomcat/Web project in Eclipse

Klaas van Gelder
Ranch Hand

Joined: Jul 08, 2004
Posts: 100
Probably this is trivial stuff.... But my last Web project is years ago and I have some troubles starting up again.
I am working on a tutorial site using Eclipse (Helios). I started the project as a JAva project. Ths Eclipse installation appears to be Web-unaware, there is no option to start a Web project.
I remember the right structure of the Web application, using a WEB-INF dir with the web.xml directory. I think the project should be made Web-aware and creating the right structyre manually should not be necessary...
Should I move the whole project to the Tomcat webapps dir and create the WEB-INF manually or is there an Eclipse plugin available to make my project WEb-aware package it into a WAR file and deploy it to the Tomcat container?
Most tutorials on this subjext appear to be pretty outdated so any advice is welcome!



"What you don't know, can't help you"
SCJP (81%), SCWCD (81%), SCJD (354/400), SCBCD (85%)
Klaas van Gelder
Ranch Hand

Joined: Jul 08, 2004
Posts: 100
This tutorial seems to offer the solution:
http://www.vogella.de/articles/EclipseWTP/article.html

I still wonder how I can "promote" my existing JAva -project to a (dynamic) Web project. Or is it better to just start a new Web project and copy the sourcefiles to the new project?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5838
    
    7

Or is it better to just start a new Web project and copy the sourcefiles to the new project?

That is what I would do.


JBoss In Action
Klaas van Gelder
Ranch Hand

Joined: Jul 08, 2004
Posts: 100
Thanks Peter, I did that
One more issue, I also have to copy the libraries, or better, attach them to the new Web-project.
It appears that there are 2 different lib directories in the web project structure:
Java Resources - Libraries
and
WEB-INF - lib

I know that libraries that are deployed with the WAR file must be placed under WEB-INF/lib
But what is the point of those 2 different folders?
It appears that, if I add an external JAR file in the normal way via Project Proerties - Java Build PAth, it becomes visible under JAva Resources - Libraries.
And one final question, what is the best location for configuration files as the hibernate.cfg.xml file?
Greetings, Klaas
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5838
    
    7

This is a guess, but I imagine that you would want to place any JAR files that you want to deploy with the WAR into the WEB-INF/lib directory, and any JARs you need to compile with but you don't want packaged with the WAR (such as the servlet.jar) should be placed into the Java Build Path (they will show up under Java Resource - Libraries).

Why a guess? I always use either Ant or Maven for my builds so I am usually only concerned with the proper JARs being in the Java BUild Path, and with m2eclipse I don't even worry about that since m2eclipse makes declaring dependencies easy and automatically handles the needs of both Eclipse and the Maven build.
 
jQuery in Action, 2nd edition
 
subject: Setting up Tomcat/Web project in Eclipse