tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rusty Wright <rusty.wri...@gmail.com>
Subject Re: Setting /WebContent as ROOT for an application
Date Sun, 14 Dec 2008 19:15:49 GMT
To add to what Alan said:

If I create a new Eclipse Dynamic Web Project, and name it MyWebApp during the project setup,
in the first window it has a drop down for Target Runtime.  That should be your installed
Tomcat on your desktop development machine; Windows in my case.  It starts out with <None>
so click the New button next to it and select, for example, Apache Tomcat v6.0, and then in
the next window use the Browse button to navigate to where Tomcat is installed (C:\Program
Files\Apache Software Foundation\apache-tomcat-v.0.18 for me).  You can leave the rest alone
and click Finish.

Next in Eclipse, do Window -> Show View -> Servers.  That creates a Servers view window
(tab) somewhere.  Click on its tab to bring it forward, then right click in the Servers window
and select New -> Server (strange that we have to do this again, but at least it's abbreviated
this time), and select Tomcat v6.0 Server (or whatever you selected when you created the project).
 Then you get the Add and Remove Projects window; double click on MyWebApp to move it to the
right into Configured projects, and click Finish.

As per the DOS tree command my Eclipse project folder/file structure is then

    |   .classpath
    |   .project
    |
    +---.settings
    |       .jsdtscope
    |       org.eclipse.jdt.core.prefs
    |       org.eclipse.jst.common.project.facet.core.prefs
    |       org.eclipse.wst.common.component
    |       org.eclipse.wst.common.project.facet.core.xml
    |       org.eclipse.wst.jsdt.ui.superType.container
    |       org.eclipse.wst.jsdt.ui.superType.name
    |
    +---build
    |   \---classes
    +---src
    \---WebContent
        +---META-INF
        |       MANIFEST.MF
        |
        \---WEB-INF
            |   web.xml
            |
            \---lib

You can ignore .classpath, .project, and .settings.  If you check your project into Subversion,
I recommend telling it to ignore those files; some people prefer checking them in.

I completely ignore the contents of the build folder; whenever you do a clean in Eclipse it
wipes and removes that folder.  The folder of interest for me is the WebContent folder; its
layout and contents is what will ultimately be in Tomcat as /usr/local/tomcat/webapps/MyWebApp
(sorry, switching to Unix parlance there).

This means that any jar files your project needs go in WebContent/WEB-INF/lib.

Also, you should create the folder WebContent/WEB-INF/classes and put in it those things that
need to be "on the classpath", for example, your logging config file (e.g., logback.xml or
log4j.xml, or log4j.properties if you prefer that confusing format), and any other properties
files and whatnot.

It's instructive to do as Alan says and do the Eclipse export to war and then list the war
file with a zip program to see what it's going to look like when Tomcat explodes it.

Static jsp files will go directly in the WebContent folder (e.g., index.jsp).  Dynamic jsp
files will probably go in some subdirectory of WEB-INF; for example, I use Spring and I've
configured it to look for the "views" in WEB-INF/views/jsp, with even more folders in that
if I'm using something like Tiles.

Back in Eclipse, in the Servers tab/window, is an entry for Tomcat, and the controls for that
are at the top of the tab; the green circle arrow starts Tomcat and when it's started the
red square stops it.  In theory, and perhaps in practice, you can edit your .java files and
do a compile/build in Eclipse and Tomcat will automatically reload them.  I'm superstitious
from back in the day when that didn't always work and try to remember to stop Tomcat before
I do a build.  This implies that I have Eclipse configured to not automatically build when
I do a Save on a file.  If Tomcat does get wedged in Eclipse; for example, changes stop showing,
you can simply delete the Tomcat instance from Eclipse by right clicking on it in the Servers
window/tab and selecting Delete, then re-add it and add your project to it.

Note that when you start and run Tomcat from within Eclipse it's not deploying your project
to your installed Tomcat; it's using the installed Tomcat's jar files and copying/creating
its own Tomcat configuration files into your project space and running it all in there.  It's
all rather magical and, surprisingly, given all the apparent black magic, works quite nicely.

It gets even more black magical if you use Maven and use the m2eclipse Maven plugin for Eclipse,
but I think it's really worth it to climb that mountain because it gives you a great base
for a consistent and maintainable project structure.


Alan Chaney wrote:
> In Eclipse, assuming you have the WTP tools installed, you create a 
> 'Dynamic Web Project.'
> This has a folder structure of which the essence is:
> 
> MyApp
>    src
>       com
>            mypackage
>                Abc.java
>    build
>       com
>          mypackage
>             Abc.class
>         WebContent
>       index.html (or jsp or whatever)
>       WEB-INF
>          web.xml
>          lib
>             a.jar
>             b.jar
> 
> In the above com.mypackage.Abc.java is your web application, and a.jar 
> and b.jar are any runtime libraries that application requires (NOT stuff 
> already in $TOMCAT_HOME/lib)
> 
> When you compile and run applications within eclipse it copies the 
> WebContent structure to the webapps directory of its (internal) tomcat, 
> and in WEB-INF creates a folder called classes and copies the contents 
> of the 'build' folder their.
> 
> This normally happens automatically every time you start the server 
> inside eclipse.
> 
> When you want to deploy the project to an external instance of tomcat 
> (eg a production server) you right-click on the Export.. option in the 
> project context menu and then select WAR (there's a suprise). The war 
> file by default has the project name (in the above expample MyApp.war. 
> This should be copied to the webapps folder of the tomcat instance and 
> if you've stuck to the normal server.xml configuration it should deploy. 
> It will be available at http://the.tomcat.instance:8080/MyApp/index.html 
> (or jspt or whatever)
> 
> This is an incredibly brief summary of what is undoubtedly an obscure 
> and complex process for the new-comer (been there.. done that...) and 
> which sadly is not especially well EXPLAINED anywhere that I have found. 
> There are some 'cookbook' type recipes on the web, which are often 
> inconsitent.
> 
> Hope that helps
> 
> Alan Chaney (a daily eclipse user, but hardly an eclipse guru...)
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Markus Schönhaber wrote:
>> Tom Blank:
>>
>>  
>>> The reason why I'm asking is, because I'm using eclipse and its
>>> 'dynamic web project' structure.
>>>     
>>
>> I'm no Eclipse user either, but AFAIR the folder "Webapps" is part of an
>> Eclipse Dynamic Web Project. And a project folder is not meant to be
>> simply copied to Tomcat's appBase (judging from your OP, it seems to me
>> that's what you've been doing).
>>
>> You could, for example, export your project to a WAR file and deploy 
>> this.
>> Experienced Eclipse users may know of other/better ways of deployment.
>> You might consider asking in the appropriate Eclipse 
>> mailinglist/newsgroup.
>>
>> Regards
>>   mks
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>> !DSPAM:4943f4d3100632009820482!
>>
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message