场景是这样的:我有一个 web 应用程序,我想使用 tomcat-maven-plugin 动态运行tomcat:运行目标 http://mojo.codehaus.org/tomcat-maven-plugin/run-mojo.html。问题是我有大量的类路径资源,这些资源需要区分打包的工件和本地工作站运行的工件。
失败的尝试:
1.) 我的第一次尝试是使用 builder-helper-maven-plugin,但它不起作用,因为目标配置文件将(不一致!)进入打包的 WAR 存档中。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${basedir}/src/main/resources-env/${testEnv}</directory>
<targetPath>${basedir}/target/classes</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
2.)我的第二次尝试是将文件夹添加到-Djava.ext.dirs(因为要部署的文件也不存在于Tomcat的类路径中),但它没有效果(我实际上怀疑这systemProperties
元素配置错误或根本无法工作)。看:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<configuration>
<tomcatWebXml>${basedir}/src/main/mock/web.xml</tomcatWebXml>
<systemProperties>
<property>
<name>java.ext.dirs</name>
<value>${basedir}/src/main/resources-env/${testEnv}</value>
</property>
</systemProperties>
<path>/licensing</path>
</configuration>
</plugin>
我不确定接下来要尝试什么。问题的核心似乎是这个插件中缺少像 Surefire 这样的东西<additionalClasspathElement>
元素。
下一步是创建自定义 catalina.properties 并将其添加到<configurationDir>
?如果是这样,catalina.properties 需要是什么样子?
编辑:更详细的解释如下
我知道这个问题读起来有些含糊,所以我会尝试详细说明一下。
我的 POM 使用 WAR 插件的 webResources 功能来复制一些特定于环境的配置文件,而不使用配置文件来完成此操作,方法是复制名为的资源/src/main/resources-env/${env}
像这样:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
...
<configuration>
...
<webResources>
<!-- Copy Environment-specific resources to classes -->
<resource>
<directory>${basedir}/src/main/resources-env/${env}</directory>
<targetPath>WEB-INF/classes</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
这会将(默认,DEV)环境资源复制到包中,并且当前工作正常。另请注意,b/c 这些是作为包装的一部分出现的,tomcat:run
他们永远不会知道目标(这是期望的,因为环境不同)。
所以问题是这样的:当动态tomcat:run
执行时,应用程序将失败,因为它的类路径(它查看target/classes
)将缺少所需的本地工作站环境配置文件。我需要做的就是在 tomcat 的路径上获取这些内容,但希望在不向命令行添加任何内容的情况下执行此操作,并且确实如果有人跟进,则不会破坏构建的完整性mvn package
并且没有clean
first.
我希望这一点更清楚。