2013-08-06 25 views
0

我試圖運行一些目標作爲戰爭包裝的編譯階段的一部分,但他們不工作。添加到編譯階段的目標沒有運行在戰爭包

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.sample</groupId> 
<artifactId>sample-test</artifactId> 
<packaging>war</packaging> 
<version>1.0</version> 
<dependencies> 
    <dependency> 
     <groupId>javax.ws.rs</groupId> 
     <artifactId>jsr311-api</artifactId> 
     <version>1.1.1</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.scannotation</groupId> 
     <artifactId>scannotation</artifactId> 
     <version>1.0.3</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-web</artifactId> 
     <version>3.1.2.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.16</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.4</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>1.6.6</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>1.6.6</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>1.17</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey.contribs</groupId> 
     <artifactId>jersey-spring</artifactId> 
     <version>1.17</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-bundle</artifactId> 
     <version>1.17</version> 
    </dependency> 
    <dependency> 
     <groupId>cglib</groupId> 
     <artifactId>cglib-asm</artifactId> 
     <version>1.0</version> 
    </dependency> 
     <dependency> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-antrun-plugin</artifactId> 
     <version>1.7</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-json</artifactId> 
     <version>1.17.1</version> 
    </dependency> 
</dependencies> 
<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <version>1.7</version> 
       <dependencies> 
        <dependency> 
         <groupId>org.apache.ant</groupId> 
         <artifactId>ant</artifactId> 
         <version>1.8.2</version> 
        </dependency> 
        <dependency> 
         <groupId>org.apache.ant</groupId> 
         <artifactId>ant-launcher</artifactId> 
         <version>1.8.2</version> 
        </dependency> 
        <dependency> 
         <groupId>org.codehaus.plexus</groupId> 
         <artifactId>plexus-utils</artifactId> 
         <version>2.0.5</version> 
        </dependency> 
       </dependencies> 
      <executions> 
       <execution> 
        <id>default-cli</id> 
        <phase>compile</phase> 
        <configuration> 
        <target> 
         <echo message ="hello"/> 
        </target> 
         <target name="get markdown.mustache"> 
         <echo message="hello ant, from Maven!"/> 
         <get dest="."> 
          <url url="https://raw.github.com/kongchen/api-doc-template/master/v1.1/markdown.mustache"/> 
         </get> 
         </target> 
        </configuration> 
        <goals> 
         <goal>run</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.10</version> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-resources-plugin</artifactId> 
       <version>2.4.3</version> 
       <configuration> 
        <encoding>UTF-8</encoding> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>copy-dependencies</goal> 
         </goals> 
         <configuration> 
          <outputDirectory>${project.build.directory}/lib 
          </outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.1</version> 
       <configuration> 
        <webXml>src\main\webapp\WEB-INF\web.xml</webXml> 
        <packagingExcludes>**/web.xml</packagingExcludes> 

       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

當我運行mvn clean installmvn clean compile然後任務maven-antrun-plugin配置沒有運行,但是當我運行mvn antrun:run然後任務正在運行。

我在做什麼錯,怎麼解決?

回答

1

你已經聲明瞭插件在<pluginManagement>這意味着你正在爲從這個pom繼承的任何pom(使這個pom成爲父)的插件定義。

如果您想直接使用此pom的插件,則需要在<build>之下直接定義<plugins>

<build> 
    <pluginManagement/> 
    <plugins> 
     <plugin> 
     ..... 
     </plugin> 
     <plugin> 
     ..... 
     </plugin> 
    </plugins> 
</build> 
+0

謝謝dmahapatro !!我浪費了我半天的時間。 :) :) – ritesh

+1

@ritesh不要擔心,當你再次遇到這種情況時,你會獲得這半天的時間。 :-) – dmahapatro

相關問題