• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat deploying my application twice

 
Ranch Hand
Posts: 157
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have an application directly copied to root folder. And i did add any context entry, as i only deployed one web application and tomcat is listening to 80 port.

But from the logs.. i observed that there are two instances of application running, which is causing duplicate entries in my DB. Anyway the duplicate entry getting failed as i have DB constraint but I need to stop getting the application deployed twice..
What could be the reason...?
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why to the root folder and not to the Webapps folder?
 
Bala Tilak
Ranch Hand
Posts: 157
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Intially i deployed to WebApps and added a context tag to map to the domain name. My colleague suggested that the context tag in config file causing the two time deployments thats why i had to remove the context entry, so i copied to ROOT folder...
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The TOMCAT_HOME/webapps folder contains all webapps deployed in Tomcat that weren't specifically designated to be somewhere else (via a TOMCAT_HOME/conf/Catalina/localhost/xxcontextnamexx.xml file or something similar).

Because Tomcat can host multiple web applications but receives the application URL requests over a common Connector channel, the URL has to contain a context path indicating which webapp will process the URL request.

For webapps deployed via the default mechanism - dropping in a WAR into TOMCAT_HOME/webapps, the name of the war file/directory is assigned to be the context pathname. So if I drop in a "myapp.war" into TOMCAT_HOME/webapps or I explode (unzip) a WAR file into TOMCAT_HOME/myapp, that app will appear at "http://myhost:8080/myapp/". The context path is "/myapp".

The one exception is the root context. That context is named "/". Because neither "/" nor "" are acceptable directory names, the alternative name "ROOT" is mapped to that particular context path.

It's important to note, however, that Tomcat typically already comes with a webapp pre-installed in TOMCAT_HOME/webapps/ROOT, so if you wish to deploy a different one, you must first undeploy and remove the original root-context webapp.

The Tomcat Manager webapp can be used to list the deployed webapps and their context paths.
 
Bala Tilak
Ranch Hand
Posts: 157
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mmm.. I tried this as well. Keep the ROOT application as is and copying the my War file to webapps. I have added a host tag in server.xml

<Host name="mydomainname.com" appBase="webapps" unpackWARs="true" autoDeploy="false">

<Context path="" docBase="mywarefilename" debug="0" privileged="true" />

</Host>

Still i see my application is deployed twice..
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try deleting the cache (work/Catalina/localhost) and restarting Tomcat?
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not add Context elements to server.xml. Context elements should be defined in their own files (under TOMCAT_HOME/conf/Catalina/localhost), the WAR's META-INF/context.xml file or similar places. Or omitted, in which case Tomcat will construct a minimal default Context. If you define a Context and you drop a WAR into TOMCAT_HOME/webapps, that would be takes as 2 distinct webapps based on the same WAR code (unless the context was in the WAR's META-INF/context.xml file).

You also do not add Host elements to server.xml unless you intend to define multiple virtual hosts. The only mods most people need to make to server.xml are for setting up TLS/SSL Connections.

For cleanest results, do the following:

1. Stop Tomcat

2. Delete everything under TOMCAT_HOME/work, TOMCAT_HOME/temp, TOMCAT_HOME/logs

3. Verify that TOMCAT_HOME/webapps contains what you want it to. It's OK (and normal) for the same webapp to be in there as both a WAR file and an exploded WAR directory. If that's the case, the directory will be used and the WAR file will be ignored. Even if it's newer than the directory.

4. Verify that you don't have anything unwanted in TOMCAT_HOME/conf/Catalina/localhost, and if you do, remove it.

5. Alternatively, just unzip a clean copy of Tomcat and use that.

6. When starting Tomcat, start it from the command shell, not as a Windows Service or via the WTP plugin that comes bundled with J2EE Eclipse (Run as Server menu). WTP mangles things and confuses the issue. Basically, you want to be running Tomcat and only Tomcat here. If you can get it to work properly stand-alone, then it's much easier to get it to run in the specialized environments.
 
Bala Tilak
Ranch Hand
Posts: 157
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim, Joe, the above fixes worked well. Thanks a lot.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic