• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 601
  • Last Modified:

programmatically create new apps on running tomcat

I am writing an app which can create additional tomcat apps at run time. a user of this app can choose from the app menu to create new apps by specifying a project name. there are no war files involved.

is it possible to programmatically update the config file so that tomcat starts to serve up this new app without shutting down?
  • 5
  • 3
2 Solutions
bhomassAuthor Commented:
why is there no hits on this one? are the points too low? is the question too vague?

even if what I want to do is not possible, it would help to hear that from an expert, so I can move on to the next option.
I think you have asked an interesting question. I think it *might be* possible to do what you propose.  I am too busy right now to do any testing. So I was just listening here.  But, since no expert has posted, I will post my ideas.
Did you look at the manager app that comes pre-installed in Tomcat ?  
or more specifically  
http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Deploy A New Application Remotely  
>I am writing an app which can create additional tomcat apps at run time  
Could you describe that code ?   Maybe you get some experts to help.
bhomassAuthor Commented:
I believe it is possible to do what I want, if I only can understand the manual. could someone please help me with some interpretation.

according to the instructions, you can add the context for individual apps without modifying server.xml, and therefore can avoid a restart. the instructions are
    *  in the $CATALINA_BASE/conf/context.xml file: the Context element information will be loaded by all webapps
    * in the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps of that host
    * in individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g. context#path.xml. The default web application may be defined by using a file called ROOT.xml.
    * if the previous file was not found for this application, in an individual file at /META-INF/context.xml inside the application files
    * inside a Host element in the main conf/server.xml

believe or not, I am not able to follow any of the items exactly.
1. $CATALINA_BASE/conf/context.xml - I know where this directory would be, but not sure if the content should be
<Context path="/foobar" docBase="/path/to/application/foobar"
2. in the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml - I don't what is enginename or hostname.
3. in individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ - I like this solution the best, but again, what is enginename and hostname?
4. in an individual file at /META-INF/context.xml - which directory is this exactly? certainly not where my docroot is, because tomcat has no way of knowing where I decide to make my doc root.

if someone can help me answer my questions, I believe I really had the answer!

I really want to find out, and have raised the points.
Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

I don't have all the answers but perhaps I can help.
>1. $CATALINA_BASE/conf/context.xml  
This probably isn't what you want to change because it is the default file for the entire server.
>2. in the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml  
Catalina is the enginename.   localhost is the hostname.
>3  see 2  
>4. in an individual file at /META-INF/context.xml  
I think this last one is what I would try first.  The META-INF folder is placed in your web app's root folder along side the WEB-INF folder. See the pre-installed "host-manager" web app for an example.

So, I would try creating your web app folder in Tomcat's webapps folder and use the manager app to deploy it( see the links I posted above here).
I have not tried this. Hopefully it will work for you.       rrz
bhomassAuthor Commented:
thanks I am going to try method 4.

I am not able to just use tomcat's webapp folder, because there is this concept of workspace (as in eclipse), which dictates some directory related to the user, not to tomcat.

I also can not use the manager interface so easily, because of the pain involved in creating a build.xml for my web apps. I am programmatically copying the .class files to the destination directory without producing a .war file.
bhomassAuthor Commented:
the host-manager web app is a poor example. the content in its web.xml is
<?xml version="1.0" encoding="UTF-8"?>

<Context antiResourceLocking="false" privileged="true" />
it contains no docbase info.

what I did is create a web.xml with the following content
<?xml version="1.0" encoding="UTF-8"?>

<Context path="/supplychain" docBase="C:/Documents and Settings/worker/workspace/workspace_supplychain/WebContent/"

and placed it in webapps/ROOT/META-INF/ just as you instructed. but when I try pulling up a file

it says resource not found.

do you see anything wrong?
bhomassAuthor Commented:
3. in individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/
this one worked!
Thanks for sharing your results. Thank you for the points
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now