为Apache Tomcat Maven插件声明额外资源仅限exec-war-only目标?

时间:2015-09-30 20:41:56

标签: java maven tomcat tomcat7-maven-plugin

我正在尝试为我的构建配置exec-war-only目标,以包含一些Extra资源(一些配置文件)。我正在使用的配置如下所示

 <plugin>
     <groupId>org.apache.tomcat.maven</groupId>
     <artifactId>tomcat7-maven-plugin</artifactId>
     <version>2.2</version>
     <executions>
         <execution>
             <phase>package</phase>
             <goals>
                 <goal>exec-war-only</goal>
             </goals>
         </execution>
     </executions>
     <configuration>
         <buildDirectory>${project.basedir}/../kmszip/</buildDirectory>
         <path>/kms</path>
         <finalName>${project.artifactId}.jar</finalName>
         <enableNaming>true</enableNaming>
         <extraResources>
             <directory>${project.basedir}/</directory>
             <includes>
                 <include>config.json</include>
             </includes>
         </extraResources>
     </configuration>
 </plugin>

使用上述配置

构建时出现以下错误
  

[错误]无法执行目标org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:项目上的exec-war-only(默认值)KeyManagementService:无法解析mojo org.apache.tomcat的配置。 maven:tomcat7-maven-plugin:2.2:exec-war-only for parameter directory:在类org.apache.tomcat.maven.plugin.tomcat7.run.ExtraResource - &gt;中找不到默认的setter。 [帮助1]

我也尝试使用以下配置<extraResources>,并得到与上面相似的错误。

<extraResources>
    <extraResource>${project.basedir}/config.json</extraResource>
</extraResources>

1 个答案:

答案 0 :(得分:0)

您错过了<extraResource>下的<extraResources>标记。正确的配置应该是:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>exec-war-only</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <buildDirectory>${project.basedir}/../kmszip/</buildDirectory>
        <path>/kms</path>
        <finalName>${project.artifactId}.jar</finalName>
        <enableNaming>true</enableNaming>
        <extraResources>
            <extraResource>
                <directory>${project.basedir}/</directory>
                <includes>
                    <include>config.json</include>
                </includes>
            </extraResource>
        </extraResources>
    </configuration>
</plugin>