4

我有一个 Maven战争项目,我正在尝试使用 tomcat7-maven-plugin 运行。我遇到的问题是每个环境的配置都在自定义文件夹中(它不在 /resources 中),因为每个环境(本地、测试、uat 或生产)都有一组不同的配置文件。

我试图弄清楚如何运行插件,同时指定一个包含本地配置目录的自定义类路径。我已经阅读了这个改进票,这样做的方法是提供一个带有Loader元素的 context.xml,但如果我这样做,webapp 将无法启动。

我在 pom 中的配置是

     <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.0</version>
        <configuration>
           <path>/${project.build.finalName}</path>
           <contextFile>${basedir}/src/env/local/context.xml</contextFile>
           <contextReloadable>true</contextReloadable>
        </configuration>
     </plugin>

context.xml 文件(tomcat 插件自动对此文件进行过滤)

<?xml version="1.0" encoding="UTF-8"?>
<Context>
   <Loader className="org.apache.catalina.loader.VirtualWebappLoader" 
           virtualClasspath="${basedir}/src/env/local/" />

   <JarScanner scanAllDirectories="true" />
</Context>

我得到的错误是

[INFO] create webapp with contextPath: /webapp
Handler error
java.lang.ClassNotFoundException: org.apache.juli.FileHandler
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:521)
        at org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:464)
        at org.apache.juli.ClassLoaderLogManager$2.run(ClassLoaderLogManager.java:377)
        at org.apache.juli.ClassLoaderLogManager$2.run(ClassLoaderLogManager.java:373)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.juli.ClassLoaderLogManager.getClassLoaderInfo(ClassLoaderLogManager.java:373)
        at org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:452)
        at org.apache.juli.ClassLoaderLogManager$2.run(ClassLoaderLogManager.java:377)
        at org.apache.juli.ClassLoaderLogManager$2.run(ClassLoaderLogManager.java:373)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.juli.ClassLoaderLogManager.getClassLoaderInfo(ClassLoaderLogManager.java:373)
        at org.apache.juli.ClassLoaderLogManager.getLogger(ClassLoaderLogManager.java:223)
        at java.util.logging.LogManager.demandLogger(LogManager.java:389)
        at java.util.logging.Logger.getLogger(Logger.java:288)
        at org.apache.juli.logging.DirectJDKLog.<init>(DirectJDKLog.java:71)
        at org.apache.juli.logging.DirectJDKLog.getInstance(DirectJDKLog.java:196)
        at org.apache.juli.logging.LogFactory.getInstance(LogFactory.java:170)
        at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:311)
        at org.apache.catalina.core.ContainerBase.getLogger(ContainerBase.java:452)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5162)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)

有没有人对如何解决这个问题或以不同的方式实现同​​样的问题有任何建议?

我已经能够使用 cargo 插件来做到这一点,但是 tomcat 插件有一些我喜欢的功能:)。

4

0 回答 0