Results 1 to 2 of 2
  1. #1
    MikeOliverAZ is offline Member
    Join Date
    Aug 2010
    Rep Power

    Question context file from war file

    Is there a way to create a context file in conf/Catalina/localhost automatically when installing a war file if the context file doesn't exist?


    Can I write a context file for my application from a Config servlet after the war file self installs?

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    it should likely be possible to use a to open, read, write the context.xml for your webapp that gets created in conf/Catalina/localhost

    This would however require
    *that your tomcat process is ran as a user has the ability to edit the files in the conf/ folder (e.g. in a hosted environment, usually not)
    *that the tomcat instance is not running with a security context that prevents the modification of the conf/ folder (usually it would)
    *that you know where the $CATALINA_BASE (or $CATALINA_HOME) (e.g. the path to this tomcat instance. I know the startup scripts work with these variables, but I am not sure they get set to Java environment variables. You might need to customize (or require that the tomcat instance be customized) to have -DCATALINA_BASE=/the/path to the tomcat instance home folder, so we can compute CATALINA_BASE/conf/localhost
    *that the application is in fact deployed into the localhost tomcat 'virtual host', otherwise the application context.xml might be in conf/myvirtualHost/Catalina right.

    But your best bet is to try to detect the absense of the special required context.xml file, such as have set some environment variable, and have something in your application detect the presence of this variable to infer the context.xml exists. When the context.xml does not exist, have the web application redirect to a setup kind of page where perhaps it generate and then print out the contents of the context.xml file with instructions for the administrator to copy and paste this content into the conf/localhost/Catalina folder. Or perhaps even have a button option to download the generated context.xml, and then have the administrator place this file into the conf/localhost/Catalina folder.

    Perhaps of interest, if you have something else to generate the context.xml file for you, the tomcat deployer http application (e.g. http://localhost:8080/manager/html) supports a deploy mode where you can specify the context.xml file and the application .war file to deploy. This unfortunately only works if you can manage to get the .war file and the context xml file onto the same machine as the tomcat instance (e.g. put these into /tmp or something). I have often been remote accessing a tomcat instance and using the upload a war file option oddly enough (as of tomcat 6.x) still doesn't have an option to specify a separate context.xml to use instead of the one inside the .war file.
    Last edited by travishein; 08-30-2010 at 04:47 AM.

Similar Threads

  1. Replies: 1
    Last Post: 08-04-2010, 03:24 PM
  2. Replies: 0
    Last Post: 07-15-2010, 01:23 PM
  3. Replies: 8
    Last Post: 02-18-2010, 01:54 PM
  4. Replies: 0
    Last Post: 02-11-2009, 10:53 AM
  5. Replies: 7
    Last Post: 05-23-2008, 03:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts