Maven:在哪里为tomcat-maven-plugin添加生成的资源? [英] Maven: Where to put generated resources for tomcat-maven-plugin?
问题描述
我的项目的 src / main / webapp
目录中有CSS和JavaScript文件。
我想加入这些资源的加入和缩小版本到我的WAR文件以及 tomcat-maven-plugin
选择它的地方。
I have CSS and JavaScript files in src/main/webapp
directory of my project.
I want to join add joined and minified version of these resources to my WAR file and to the place where tomcat-maven-plugin
picks it up.
我使用yuicompressor-maven-plugin创建文件并将其放入 $ {project.build.directory} / $ {project.build.finalName}
。它适用于maven包,并且这些资源进入WAR文件,但不知何故 tomcat-maven-plugin
根本看不到它们。我应该使用不同的目录吗?
I used yuicompressor-maven-plugin to create the files and put it to ${project.build.directory}/${project.build.finalName}
. It works great for maven package and those resources make their way to WAR file, but somehow tomcat-maven-plugin
does not see those at all. Should I use a different directory for it?
我的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 :运行
以获取我生成的文件?
What should I do to make mvn tomcat:run
to also pick up my generated files?
推荐答案
使用 warSourceDirectory
:
<warSourceDirectory>${project.build.directory}/${project.build.finalName}</warSourceDirectory>
而不是此配置属性( warDirectory
)对于 tomcat-maven-plugin
:
Instead of this configuration property (warDirectory
) for the tomcat-maven-plugin
:
<warDirectory>${project.build.directory}/${project.build.finalName}</warDirectory>
根据 tomcat-maven-plugin documentation , warSourceDirectory
是获取网络资源的地方,它的默认值是 $ {basedir} / src / main / webapp
。这意味着如果您没有设置该属性,则需要在 $ {basedir} / src / main / webapp
下生成统一/缩小的JavaScript文件。
According to the tomcat-maven-plugin documentation, warSourceDirectory
is where the web resources get picked up, and its default value is ${basedir}/src/main/webapp
. This means that if you don’t set that property, you need to generate your unified/minified JavaScript file under ${basedir}/src/main/webapp
.
如果将 warSourceDirectory
设置为输出文件夹,则表示您需要在启动Tomcat之前生成此文件。
If you set warSourceDirectory
to the output folder, this means you need to generate this file before starting Tomcat.
这篇关于Maven:在哪里为tomcat-maven-plugin添加生成的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!