Results 1 to 2 of 2
Thread: context file from war file
- 08-30-2010, 01:49 AM #1Member
- Join Date
- Aug 2010
- Rep Power
- 08-30-2010, 05:41 AM #2
it should likely be possible to use a java.io.File 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 05:47 AM.
- By maheshsardar in forum Java AppletsReplies: 1Last Post: 08-04-2010, 04:24 PM
- By msegmx in forum Advanced JavaReplies: 0Last Post: 07-15-2010, 02:23 PM
- By al_Marshy_1981 in forum NetworkingReplies: 8Last Post: 02-18-2010, 01:54 PM
- By mahendra.athneria in forum New To JavaReplies: 0Last Post: 02-11-2009, 10:53 AM
- By padmajap13 in forum Advanced JavaReplies: 7Last Post: 05-23-2008, 04:46 AM