2013-05-17 43 views
0

我有3個項目:父項目,基礎項目和演示項目。Maven覆蓋:基地項目總是在安裝時啓動tomcat

母公司是全球插件和依賴:

<?xml version="1.0" encoding="UTF-8"?> 
<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/xsd/maven-4.0.0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.example</groupId> 
    <artifactId>parent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 

    <packaging>pom</packaging> 

    <properties> 

     <!-- Generic properties --> 
     <java.version>1.6</java.version> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 

     <!-- Spring --> 
     <spring.version>3.2.2.RELEASE</spring.version> 

     <!-- Servlet --> 
     <jstl.version>1.2</jstl.version> 
     <servlet.version>2.5</servlet.version> 

     <!-- Logging --> 
     <slf4j.version>1.7.5</slf4j.version> 
     <log4j.version>1.2.17</log4j.version> 

     <!-- Test --> 
     <junit.version>4.11</junit.version> 

     <!-- Apache Tiles --> 
     <tiles.version>2.2.2</tiles.version> 

    </properties> 

    <dependencies> 

     <!-- Spring --> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context</artifactId> 
      <version>${spring.version}</version> 
      <exclusions> 
       <!-- Exclude Commons Logging in favor of SLF4j --> 
       <exclusion> 
        <groupId>commons-logging</groupId> 
        <artifactId>commons-logging</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 

     <!-- Servlet --> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>servlet-api</artifactId> 
      <version>${servlet.version}</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>jstl</artifactId> 
      <version>${jstl.version}</version> 
     </dependency> 

     <!-- Logging --> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>${slf4j.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>jcl-over-slf4j</artifactId> 
      <version>${slf4j.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
      <version>${slf4j.version}</version> 
      <scope>runtime</scope> 
     </dependency> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>${log4j.version}</version> 
      <scope>runtime</scope> 
     </dependency> 

     <!-- Test --> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>${junit.version}</version> 
     </dependency> 

     <!-- Apache Tiles --> 
     <dependency> 
      <groupId>org.apache.tiles</groupId> 
      <artifactId>tiles-jsp</artifactId> 
      <version>${tiles.version}</version> 
      <exclusions> 
       <!-- Exclude Commons Logging in favor of SLF4j --> 
       <exclusion> 
        <groupId>commons-logging</groupId> 
        <artifactId>commons-logging-api</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 

    </dependencies> 

    <build> 

     <defaultGoal>install</defaultGoal> 

     <plugins> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.0</version> 
       <configuration> 
        <compilerArguments> 
         <Xlint /> 
        </compilerArguments> 
        <verbose>true</verbose> 
        <source>${java.version}</source> 
        <target>${java.version}</target> 
        <showWarnings>true</showWarnings> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.3</version> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.tomcat.maven</groupId> 
       <artifactId>tomcat7-maven-plugin</artifactId> 
       <version>2.0</version> 
       <configuration> 
        <webXml>src/main/webapp/WEB-INF/web.xml</webXml> 
       </configuration> 
       <executions> 
        <execution> 
         <id>tomcat-run</id> 
         <goals> 
          <goal>run</goal> 
         </goals> 
         <phase>pre-integration-test</phase> 
        </execution> 
        <execution> 
         <id>tomcat-shutdown</id> 
         <goals> 
          <goal>shutdown</goal> 
         </goals> 
         <phase>post-integration-test</phase> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 

    </build> 

</project> 

基地是基本的Spring配置(Servlet中,控制器,...):

<?xml version="1.0" encoding="UTF-8"?> 
<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/xsd/maven-4.0.0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.example</groupId> 
    <artifactId>base</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 

    <packaging>war</packaging> 

    <parent> 
     <groupId>com.example</groupId> 
     <artifactId>parent</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </parent> 

    <build> 
     <defaultGoal>install</defaultGoal> 
    </build> 

</project> 

和演示的Spring JSP的東西:

<?xml version="1.0" encoding="UTF-8"?> 
<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/xsd/maven-4.0.0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.example</groupId> 
    <artifactId>demo</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 

    <packaging>war</packaging> 

    <parent> 
     <groupId>com.example</groupId> 
     <artifactId>parent</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </parent> 

    <dependencies> 
     <dependency> 
      <groupId>com.example</groupId> 
      <artifactId>base</artifactId> 
      <version>0.0.1-SNAPSHOT</version> 
      <scope>runtime</scope> 
      <type>war</type> 
     </dependency> 
    </dependencies> 

    <build> 
     <defaultGoal>tomcat:run</defaultGoal> 
    </build> 

</project> 

安裝父就像一個魅力(能找到它在當地的M2存儲庫),但章安lling基礎項目總是運行tomcat?我只想構建戰爭並將其安裝在本地m2存儲庫中。這裏有什麼問題?

ps:我不喜歡總是提到依賴和插件,所以將它們留在父項目中是非常好的,因爲我需要它們在每個孩子(例如演示)項目中。

回答

1

您的defaultGoalinstall而您在pre-integration-test上綁定tomcat-run。因此,只要啓動maven install,它就會在執行pre-integration-test階段時執行tomcat-run

簽出maven生命週期:http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html瞭解。

所以你應該更新你的tomcat7-maven-plugin並刪除執行。如果你仍然想保留這些,那麼你應該考慮使用一些profiles(一個特定的配置文件,例如建築物)