我的项目的 src/main/webapp
目录中有 CSS 和 JavaScript 文件。
我想将这些资源的合并和缩小版本添加到我的 WAR 文件和 tomcat-maven-plugin
获取它的地方。
我使用 yuicompressor-maven-plugin 创建文件并将其放入 ${project.build.directory}/${project.build.finalName}
。它非常适用于 Maven 包,这些资源会进入 WAR 文件,但不知何故 tomcat-maven-plugin
根本看不到这些。我应该为它使用不同的目录吗?
我的pom:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<path>/MyApp</path>
<warDirectory>${project.build.directory}/${project.build.finalName}</warDirectory>
</configuration>
</plugin>
<plugin>
<version>2.5.1</version>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<optimize>true</optimize>
<debug>true</debug>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/resources/META-INF</directory>
<filtering>true</filtering>
<targetPath>META-INF</targetPath>
<includes>
<include>context.xml</include>
</includes>
</resource>
</webResources>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<excludes>
<exclude>**/*</exclude>
</excludes>
<aggregations>
<aggregation>
<output>${project.build.directory}/${project.build.finalName}/js/commons-pack.js</output>
<includes>
<include>${project.build.sourceDirectory}/../webapp/js1.js</include>
<include>${project.build.sourceDirectory}/../webapp/js2.js</include>
...
我应该怎么做才能使 mvn tomcat:run
也获取我生成的文件?
最佳答案
使用warSourceDirectory
:
<warSourceDirectory>${project.build.directory}/${project.build.finalName}</warSourceDirectory>
代替 tomcat-maven-plugin
的配置属性 (warDirectory
):
<warDirectory>${project.build.directory}/${project.build.finalName}</warDirectory>
根据tomcat-maven-plugin documentation ,warSourceDirectory
是web资源获取的地方,它的默认值是${basedir}/src/main/webapp
。这意味着如果您不设置该属性,则需要在 ${basedir}/src/main/webapp
下生成统一/缩小的 JavaScript 文件。
如果您将warSourceDirectory
设置为输出文件夹,这意味着您需要在启动Tomcat之前生成该文件。
关于java - Maven:将生成的 tomcat-maven-plugin 资源放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12570768/