代码之家  ›  专栏  ›  技术社区  ›  user1547039

Maven:tomcat Maven插件生成的资源放在哪里?

  •  14
  • user1547039  · 技术社区  · 12 年前

    我有CSS和JavaScript文件 src/main/webapp 我项目的目录。 我想加入-将这些资源的加入和缩小版本添加到我的WAR文件和 tomcat-maven-plugin 把它捡起来。

    我使用yuicompressor maven插件创建文件并将其放入 ${project.build.directory}/${project.build.finalName} .它对maven包非常有效,这些资源会进入WAR文件,但不知何故 tomcat maven插件 根本看不到这些。我应该为它使用不同的目录吗?

    我的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 还要提取我生成的文件?

    3 回复  |  直到 12 年前
        1
  •  5
  •   Sébastien Le Callonnec    12 年前

    使用 warSourceDirectory 以下为:

    <warSourceDirectory>${project.build.directory}/${project.build.finalName}</warSourceDirectory>
    

    而不是此配置属性( warDirectory )对于 tomcat-maven-plugin 以下为:

    <warDirectory>${project.build.directory}/${project.build.finalName}</warDirectory>
    

    根据 tomcat-maven-plugin documentation , warSource目录 是获取web资源的位置,其默认值为 ${basedir}/src/main/webapp 。这意味着,如果你不设置该属性,你需要在 ${basedir}/src/main/webapp

    如果你设置 warSource目录 到输出文件夹,这意味着您需要在启动Tomcat之前生成此文件。

        2
  •  3
  •   sgdesmet    12 年前

    或者,您也可以使用 run-war 目标而不是 run ,例如。 mvn tomcat6:run-war .这将使用构建目录中的爆炸战争(以及由此过滤的资源)。看见 this site 。还有 run-war-only 其跳过封装阶段。

        3
  •  1
  •   Olivier Lamy    12 年前

    请注意,该插件现在在Apache上维护(所以升级一点:-))请参阅 http://tomcat.apache.org/maven-plugin-2.0/

    即使它使用install也能工作,我不确定它是否是最佳解决方案(关于io和构建时间)。

    tomcat运行必须能够使用多个目录中的资源(我不确定当前tomcat嵌入的api是否可能)。

    你能在这里添加功能请求吗 https://issues.apache.org/jira/browse/MTOMCAT

    谢谢