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?
bhomassAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
0
rrzCommented:
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 ?  
http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html 
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.
0
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"
         debug="0">
</Context>
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.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

rrzCommented:
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.
yourTomcatHome/conf/Catalina/localhost/context.xml
>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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
0
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/"
         debug="0">
</Context>

and placed it in webapps/ROOT/META-INF/ just as you instructed. but when I try pulling up a file
http://localhost:8080/supplychain/signin.html

it says resource not found.

do you see anything wrong?
0
bhomassAuthor Commented:
3. in individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/
this one worked!
0
rrzCommented:
Thanks for sharing your results. Thank you for the points
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java App Servers

From novice to tech pro — start learning today.