2

WEB-INF/config/无论我是否打电话,我都在努力确保将正确的资源转移到

mvn gcloud:deploy

或者

mvn tomcat7:run 

这就是为什么我要强制-Dpackage-mode=<value>设置。我正在使用这样maven-resource-plugin的复制部分:

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>validate</id>
            <phase>validate</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>src/main/webapp/WEB-INF/config</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/assembly/${package-mode}/config</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

但是,如果我运行

mvn validate tomcat7:run -Dpackage-mode=dev 

为了启动服务器,文件没有被复制。

E:\java\mz\mz-server\mz-web-server>mvn validate tomcat7:run -Denv=dev -Dpackage-mode=dev
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mz-web-server 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) @ mz-web-server ---
[INFO]
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-property) @ mz-web-server ---
[INFO]
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ mz-web-server >>>
[INFO]
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) @ mz-web-server ---
[INFO]
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-property) @ mz-web-server ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mz-web-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ mz-web-server ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ mz-web-server <<<
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ mz-web-server ---
[INFO] Running war on http://localhost:8080/
[INFO] Using existing Tomcat server configuration at E:\java\mz\mz-server\mz-web-server\target\tomcat
[INFO] setting SystemProperties:
[INFO]  gwt.codeserver.port=9876
[INFO] create webapp with contextPath:
Jun 03, 2016 5:24:57 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jun 03, 2016 5:24:57 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Jun 03, 2016 5:24:57 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
...

我在这里做错了什么?我实际上不知道validate这里是否是一个不错的选择,而且我并没有真正受制于某个阶段。我想要的只是确保根据package-mode.

但:

如果我只是跑

mvn validate -Dpackage-mode=dev 

然后一切都按预期工作 - 文件正在被复制。

4

1 回答 1

2

您不应该使用maven-resources-plugin来复制 webapp 资源,此插件仅适用于应用程序资源。此外,您永远不应该在 .下生成或复制文件src,就像您正在使用<outputDirectory>src/main/webapp/WEB-INF/config</outputDirectory>. 生成的文件应始终放在该target文件夹下。

相反,使用maven-war-plugin. 您可以将其配置为过滤特定目录并将其输出到 WAR 中,如下所示:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.6</version>
  <configuration>
    <webResources>
      <resource>
        <directory>src/main/assembly/${package-mode}/config</directory>
        <filtering>true</filtering>
        <targetPath>WEB-INF/config</targetPath>
      </resource>
    </webResources>
  </configuration>
</plugin>

这将过滤目录src/main/assembly/${package-mode}/config并将其下的文件WEB-INF/config放在 WAR 的目标文件夹中。

通过此更改,您将能够运行您的 web 应用程序mvn clean tomcat7:run-war(而不是tomcat7:run因为它不会打包 WAR)。

于 2016-06-03T15:24:47.630 回答