Adding a directory to tomcat classpath

I have a folder in my C: drive as C:app_configjava_app This folder contains some locale specific property files.

I have a java class ( PrjPropertilesLocator ) that loads the property files based on default locale on the startup of the web App.My web application is running inside tomcat. The problem is how should i set this directory C:app_configjava_app in the tomcat classpath so that this becomes available to the ResourceBundle inside the PrjPropertilesLocator class. Is there a way i can set this folder specifically for a Single web app that needs it.I do not want to put the property files inside WEB-INF/classes folder.

On weblogic this runs fine.I set the directory inside the weblogic classpath in one of its startup scripts and it works fine. But on Tomcat i tried putting it in startup.bat also in setclasspath.bat , but was not able to do so successfully.


只需在shared.loadercommon.loader属性中指定它/conf/catalina.properties


See also question: Can I create a custom classpath on a per application basis in Tomcat

Tomcat 7 Context hold Loader element. According to docs deployment descriptor (what in <Context> tag) can be placed in:

  • $CATALINA_BASE/conf/server.xml - bad - require server restarts in order to reread config
  • $CATALINA_BASE/conf/context.xml - bad - shared across all applications
  • $CATALINA_BASE/work/$APP.war:/META-INF/context.xml - bad - require repackaging in order to change config
  • $CATALINA_BASE/work/[enginename]/[hostname]/$APP/META-INF/context.xml - nice, but see last option!!
  • $CATALINA_BASE/webapps/$APP/META-INF/context.xml - nice, but see last option!!
  • $CATALINA_BASE/conf/[enginename]/[hostname]/$APP.xml - best - completely out of application and automatically scanned for changes!!!
  • Here my config which demonstrate how to use development version of project files out of $CATALINA_BASE hierarchy (note that I place this file into src/test/resources dir and intruct Maven to preprocess ${basedir} placeholders through pom.xml <filtering>true</filtering> so after build in new environment I copy it to $CATALINA_BASE/conf/Catalina/localhost/$APP.xml ):

    <Context docBase="${basedir}/src/main/webapp"
             reloadable="true">
        <!-- http://tomcat.apache.org/tomcat-7.0-doc/config/context.html -->
        <Resources className="org.apache.naming.resources.VirtualDirContext"
                   extraResourcePaths="/WEB-INF/classes=${basedir}/target/classes,/WEB-INF/lib=${basedir}/target/${project.build.finalName}/WEB-INF/lib"/>
        <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
                virtualClasspath="${basedir}/target/classes;${basedir}/target/${project.build.finalName}/WEB-INF/lib"/>
        <JarScanner scanAllDirectories="true"/>
    
        <!-- Use development version of JS/CSS files. -->
        <Parameter name="min" value="dev"/>
        <Environment name="app.devel.ldap" value="USER" type="java.lang.String" override="true"/>
        <Environment name="app.devel.permitAll" value="true" type="java.lang.String" override="true"/>
    </Context>
    

    UPDATE Tomcat 8 change syntax for <Resources> and <Loader> elements, corresponding part now look like:

    <Resources>
        <PostResources className="org.apache.catalina.webresources.DirResourceSet"
                       webAppMount="/WEB-INF/classes" base="${basedir}/target/classes" />
        <PostResources className="org.apache.catalina.webresources.DirResourceSet"
                       webAppMount="/WEB-INF/lib" base="${basedir}/target/${project.build.finalName}/WEB-INF/lib" />
    </Resources>
    

    In Tomcat 6, the CLASSPATH in your environment is ignored. In setclasspath.bat you'll see

    set CLASSPATH=%JAVA_HOME%libtools.jar
    

    then in catalina.bat, it's used like so

    %_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% 
    -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" 
    -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" 
    -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
    

    I don't see any other vars that are included, so I think you're stuck with editing setclasspath.bat and changing how CLASSPATH is built. For Tomcat 6.0.20, this change was on like 74 of setclasspath.bat

    set CLASSPATH=C:app_configjava_app;%JAVA_HOME%libtools.jar
    
    链接地址: http://www.djcxy.com/p/23316.html

    上一篇: Java EE web开发,我从哪里开始,我需要什么技能?

    下一篇: 将目录添加到tomcat classpath