2

Problem. I have various environment-specific configuration files that I want to include on the classpath at runtime, but I don't want these to be part of the WAR itself. For example, I have a log4j.xml file for the dev environment with debugging turned on, and a properties file with lots of environment-specific credentials, endpoints and so forth.

I want these outside the WAR because I want to release the same WAR I test, rather than building separate environment-specific WARs. I could potentially include multiple environment-specific sets of configuration in the WAR (similar to the profile capability that both Maven and Spring provide), but I prefer not to.

Standalone Tomcat has the shared.loader feature (in catalina.properties), and Jetty has extraClasspath, but I don't know how to do this with the Gradle Tomcat plugin. Is there a way?

Related posts. The following posts are related, but they seem to involve copying the configuration files into locations that end up being pulled into the WAR file.

Community
  • 1
  • 1

2 Answers2

2

Figured out a way to do this:

buildscript {
    repositories { mavenCentral() }
    dependencies {
        classpath "org.gradle.api.plugins:gradle-tomcat-plugin:0.9.7"
        classpath files("/path/to/config/files")
    }
}
0

You could try to use the property additionalRuntimeJars for this. The name is a little bit off but the purpose is to add external JARs to Tomcat's classloader.

[tomcatRun, tomcatRunWar]*.additionalRuntimeJars << file("/path/to/config/files")

or

[tomcatRun, tomcatRunWar]*.additionalRuntimeJars = [file("/path/to/config/files")]

I am not sure if it is going to work but it's worth a try. If that doesn't work it would be great if you could open an issue for it on GitHub.

Benjamin Muschko
  • 32,442
  • 9
  • 61
  • 82
  • Sounds good Benjamin. I'll take a look at that. If this works, my thought is that this approach is superior to the answer I posted because it limits the scope of the extra classpathing to the Tomcat plugin. Note thought that I'm adding a directory of config files rather than adding JARs, so we'll see. –  Feb 28 '13 at 17:36
  • I looked at AbstractTomcatRunTask. The property name (additionalRuntimeJars) is correct, but it's not working using either of the suggested formulations. I'll create the issue. Thanks again. –  Feb 28 '13 at 17:46
  • For those who want to follow it: https://github.com/bmuschko/gradle-tomcat-plugin/issues/41 –  Feb 28 '13 at 17:59
  • With version 2.2.1 of the plugin the property has been renamed to `additionalRuntimeResources`. It works properly for me. – Benjamin Muschko May 09 '15 at 15:16