struts在哪里寻找配置文件?

时间:2013-01-29 20:49:13

标签: java struts-1

我继承了一个Struts 1应用程序,该应用程序由大约8个独立的包组成,所有包都编译到同一个应用程序我的任务是重写它的ant构建脚本。以前它将所有配置文件分别复制到/ usr / local / tomcat / shared / classes目录中,但是我们的ops团队要求我们简化一些事情,以便构建脚本只创建一个可以放入tomcat的war文件。 / p>

我的ConfigurationManager类尝试加载其配置文件时出错。这个文件config.xml目前正在被应用到其他应用程序之前被复制到WEB-INF中。因此,当我看到爆炸的战争(ROOT)时,我确实找到了/usr/local/tomcat/webapps/ROOT/WEB-INF/config.xml。以下是ConfigurationManager的相关部分:

private static final String BASE_CONFIG_FILE = "WEB-INF/config.xml";

private void loadConfigFiles() throws RCConfigurationException {
    try {
        log.error("classpath: " + System.getProperty("java.class.path"));

        ConfigurationFactory factory = new ConfigurationFactory();
        URL configURL = getClass().getResource(BASE_CONFIG_FILE);
        factory.setConfigurationURL(configURL);
        config = factory.getConfiguration();

    } catch (ConfigurationException e) {
        log.error("Exception loading configuration files.", e);
        throw new RCConfigurationException("Exception loading configuration files", e);
    }
}

log.error()调用输出:

13:16:10,561 ERROR ConfigurationManager:75 - classpath: /usr/local/tomcat/bin/bootstrap.jar

我的localhost.2013-01-29.log显示了这个:

SEVERE: Exception starting filter GlobalRootManager
java.lang.ExceptionInInitializerError
    at com.rc.util.config.ConfigurationManager.getInstance(ConfigurationManager.java:66)
    at com.rc.commonbusinesswebapp.servlet.filter.GlobalRootManager.init(GlobalRootManager.java:42)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
    at org.apache.commons.configuration.ConfigurationFactory.setConfigurationURL(ConfigurationFactory.java:220)
    at com.rc.util.config.ConfigurationManager.loadConfigFiles(ConfigurationManager.java:79)
    at com.rc.util.config.ConfigurationManager.<init>(ConfigurationManager.java:55)
    at com.rc.util.config.ConfigurationManager.<init>(ConfigurationManager.java:26)
    at com.rc.util.config.ConfigurationManager$LazyHolder.<clinit>(ConfigurationManager.java:37)
    ... 29 more

我正在转动轮子,所以我希望有人可以帮助我。感谢。

1 个答案:

答案 0 :(得分:3)

WEB-INF不在网络应用的类路径中。

WEB-INF/classes是;如果要将配置文件作为类路径资源加载,一个选项是将文件定位在类路径的根目录。