src/main/webapp我的项目目录中有CSS和JavaScript文件。我想将这些资源的合并和缩小版本添加到我的WAR文件以及将其tomcat- maven-plugin拾取的位置。
src/main/webapp
tomcat- maven-plugin
我使用yuicompressor-maven- plugin创建文件并将其放入${project.build.directory}/${project.build.finalName}。它对maven包非常有用,那些资源进入了WAR文件,但是某种程度上tomcat- maven-plugin根本看不到。我应该使用其他目录吗?
${project.build.directory}/${project.build.finalName}
我的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拾取生成的文件?
mvn tomcat:run
用途warSourceDirectory:
warSourceDirectory
<warSourceDirectory>${project.build.directory}/${project.build.finalName}</warSourceDirectory>
代替此配置属性(warDirectory)tomcat-maven-plugin:
warDirectory
tomcat-maven-plugin
<warDirectory>${project.build.directory}/${project.build.finalName}</warDirectory>
根据tomcat-maven-plugin文档,warSourceDirectoryWeb资源是从此处获取的,其默认值为${basedir}/src/main/webapp。这意味着,如果您未设置该属性,则需要在下生成统一/最小化的JavaScript文件${basedir}/src/main/webapp。
${basedir}/src/main/webapp
如果设置warSourceDirectory为输出文件夹,则意味着您需要在启动Tomcat之前生成此文件。