-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Mathieu,
On 10/23/19 17:23, Mathieu Dubois wrote: > I noticed that the application also need to access to a directory > to store the result of some computation usually outside the > location of tomcat (the results can be rather large). As for the DB > this depends on each instance of the application. Is there a > similar mechanism for such a case ? It's not exactly clear what you are asking, but it sounds like you are looking for a configuration similar to the JNDI binding that can be split between conf/server.xml and META-INF/context.xml for connecting to a database. You have some choices, here, and the "right one" probably will require you to make a decision based upon your requirements. In WEB-INF/web.xml, there are some optional configuration data called "context parameters". They look something like this: <?xml version="1.0"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0" metadata-complete="true"> <context-param> <description> You can put whatever you want in here. It's just documentation for human readers. </description> <param-name>my-configuration-property-name</param-name> <param-value>my value</param-value> </context-param> ... </web-app> If you want to put, for example, a directory path in here for storing temporary files, you could do it like this: <web-app> <context-param> <description>Path to the temporary file directory where we write filed.</description> <param-name>fr.cns.genoscope.appname.tmpfiledir</param-name> <param-value>/tmp/app/temp-files</param-value> </context-param> ... </web-app> In order to use these configuration values, your code needs to read them explicitly, so you'll need to make some code changes in order to put your configuration into WEB-INF/web.xml. Something like this in your servlet: String tmpDir = getServletContext().getInitParam("fr.cns.genoscope.appname.tmpfiledir"); // ... use the tmpDir for all your file-writing needs Now, WEB-INF/web.xml is bundled inside your WAR file and, as you've mentioned, it's not very flexible with your builds. So, here's what you can do: The file META-INF/context.xml (also bundled within your application's WAR file -- hold that thought for a minute) can be used to override the values of your context-param values, like this: <?xml version="1.0"?> <Context> <Parameter name="fr.cns.genoscope.appname.tmpfiledir" value="/usr/local/other/location/for/client/X" override="true"/> ... </Context> More info can be found at: http://tomcat.apache.org/tomcat-9.0-doc/config/context.html#Context_Para meters So, you could put the right value into WEB-INF/web.xml (which is inconvenient) or into META-INF/context.xml (which is also inconvenient) or -- and here's where things get a little interesting - -- you can copy the file META-INF/context.xml from the WAR file and put it into Tomcat's configuration directory structure like this: conf/[enginename]/[hostname]/[appname].xml ...and it will *override* the file supplied by the WAR file in META-INF/context.xml. So you get to use the same WAR file everywhere and customize those XML files on a per-client basis. Above, the [enginename] is almost always "Catalina" and matches the "name" attribute of the <Engine> in your conf/server.xml file. By default, it's name="Catalina" and pretty much nobody ever changes it. Your [hostname] comes from the "name" attribute of the <Host> in which your context/webapp is defined, and is often just "localhost" although it would be anything depending upon your environment. The [appname] is whatever you want it to be: the [appname] sets the context-path of the application. But the [appname].xml must match your [appname].war file name. So if you don't mind modifying your code a little, this can get your a lot of flexibility. This feature goes back to Tomcat 5.5, so you should be able to use it. I'd of course encourage you to look at upgrading to at least Tomcat 8.5 in the near-term. You may find that you can just drop-in the latest Tomcat 8.5.x in place of your Tomcat 5.5 and everything still works. (You will have to re-write your conf/server.xml file from scratch, as those files are not compatible between major releases.) Hope that helps, - -chris -----BEGIN PGP SIGNATURE----- Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/ iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl2w1gAACgkQHPApP6U8 pFit/g/9EXtTvtvhpbnPxZnObyg+sUjhoFuZI7/Dmczhq03ZzLi+H51KoplM9F3Q 8xDLtunDZrkGQfb2g95Uh7fI4K0rthRzE2UQ6uS7jkodDKNwHuH+dKibUADIDEoF 1DYqHhEzN7v5yZg9ohERs9fI0hzqNutcNqmfquFdnZ7sN9LWh3SOxdkUa1dYooZj xRNbkZ7/xjULyYEHTEljzQ4n541UDE05qNYQPf+UKCduUcUeTlaS3sJIp8YNa+uT lnFASUZnsH6CDWU99cYmPdi8GB0Bntt/Ib6QpYeZter6nYKOU/2Hc6Ga6pD5dCTo DW+kJ008OWzYsROj137Orr9MaSPbvRD7kpCTieADaY9fzUEL2pyQmaY5l0h6uQTN 2sHTE4CIAwL/osKBRkUSZcsEwWMitPxCRiJhIwLn0ae97w3Fd0h9wIag2bzTuf+X k3CdjhMSSWauhMdlCG9R3kWNfa4ZM5Xn2yVQnCpcR6GfRwwNY7I+EHQVwVi5fl45 QrCDlDyOxJ+FHaedlczrVdCDqAdyieOdsuSlirwbRrYlCClzD+LMAofTRGxvDNvs lSvl6ove3yhsFGdyNz9C+YDnDyIG9c5QK+Wy0R2LCki9UZ1ynA5WCwuQWw44kTRh rFeCK3zvQNLcytWIshhK09a3ZeDsMKZnGx+n3lmuA18dOprJ6jg= =MT/7 -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org