2013-05-22 98 views
1

當前我正在嘗試配置maven到本地存儲庫,例如:c:/maven-repo/repository。爲此,我更改了M2_HOME/conf/settings.xml中的<localRepository>值,並將其指向上述路徑。Maven本地存儲庫和編譯

當我通過命令提示符執行任何mvn命令時,所有需要的maven依賴關係都將geting下載到給定的本地回購路徑。

但是,當我使用mvn -e clean install作爲項目之一時,maven能夠將所需的依賴項下載到本地存儲庫路徑,但編譯失敗。

當我把settings.xml置於${user.home}/.m2位置mvn clean install執行成功。

請注意:${user.home}/.m2/repository下和本地存儲庫路徑下的依賴項是相同的。

是否有任何設置,需要在maven中完成,以便maven可以使用本地存儲庫路徑下的依賴關係而不是${user.home}/.m2/repository路徑。

我父母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.mycomp.test</groupId> 
<artifactId>ProjectArtifact</artifactId> 
<version>2.1</version> 
<packaging>pom</packaging> 
<name>Acrts</name> 
<description>Parent Project</description> 
<properties> 
    <!-- tests librairies version --> 
    <junit.version>4.7</junit.version> 

    <!-- tools version --> 
    <maven.version>2.0</maven.version> 
    <java.source.version>1.7</java.source.version> 
    <java.target.version>1.7</java.target.version> 
</properties> 
<dependencies> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>${log4j.version}</version> 
     <exclusions> 
      <exclusion> 
       <groupId>javax.mail</groupId> 
       <artifactId>mail</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>javax.jms</groupId> 
       <artifactId>jms</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>com.sun.jdmk</groupId> 
       <artifactId>jmxtools</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>com.sun.jmx</groupId> 
       <artifactId>jmxri</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
</dependencies> 
<build> 
    <!--  <finalName>should_not_be_used</finalName>--> 
    <extensions> 
     <!-- Enabling the use of FTP --> 
     <extension> 
      <groupId>org.apache.maven.wagon</groupId> 
      <artifactId>wagon-ftp</artifactId> 
      <version>1.0-beta-6</version> 
     </extension> 
    </extensions> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>${java.source.version}</source> 
       <target>${java.target.version}</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2-beta-4</version> 
      <configuration> 
       <descriptors> 
        <descriptor>../Acrts/ACS_assembly.xml</descriptor> 
        <!--<descriptor>../Pub/ACS_assembly.xml</descriptor>--></descriptors> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-deploy-plugin</artifactId> 
      <version>2.5</version> 
      <executions> 
       <execution> 
        <phase>deploy</phase> 
        <goals> 
         <goal>deploy</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <!--<plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <configuration> 
       <skip>true</skip> 
      </configuration> 
     </plugin> 
    --></plugins> 
</build> 
</project> 

而我的主要項目pom.xml是:

<?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/maven-v4_0_0.xsd"> 

<parent> 
    <artifactId>ProjectArtifact</artifactId> 
    <groupId>com.mycomp.test</groupId> 
    <version>2.1</version> 
</parent> 

<properties> 
    <!-- Convenience property to set the GWT version --> 
    <gwtVersion>2.5.1</gwtVersion> 
    <!-- GWT needs at least java 1.5 --> 
    <maven.compiler.source>1.7</maven.compiler.source> 
    <maven.compiler.target>1.7</maven.compiler.target> 
    <web.inf.lib>WEB-INF/lib</web.inf.lib> 
</properties> 

<!-- POM file generated with GWT webAppCreator --> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.mycomp.test</groupId> 
<artifactId>MainProjectServer</artifactId> 
<packaging>war</packaging> 
<version>${project.release.version}</version> 
<name>AcrtsGwtServer</name> 

<dependencies> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>apache-log4j-extras</artifactId> 
     <version>1.1</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-dbcp</groupId> 
     <artifactId>commons-dbcp</artifactId> 
     <version>1.4</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-lang</groupId> 
     <artifactId>commons-lang</artifactId> 
     <version>2.6</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hsqldb</groupId> 
     <artifactId>hsqldb</artifactId> 
     <version>2.0.0</version> 
    </dependency> 
    <dependency> 
     <groupId>jfree</groupId> 
     <artifactId>jfreechart</artifactId> 
     <version>1.0.13</version> 
    </dependency> 
    <dependency> 
     <groupId>jfree</groupId> 
     <artifactId>jcommon</artifactId> 
     <version>1.0.15</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-io</artifactId> 
     <version>1.3.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-compress</artifactId> 
     <version>1.1</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
     <version>3.1</version> 
    </dependency> 

    <dependency> 
     <groupId>commons-fileupload</groupId> 
     <artifactId>commons-fileupload</artifactId> 
     <version>1.2.2</version> 
    </dependency> 
    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-servlet</artifactId> 
     <version>${gwtVersion}</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-user</artifactId> 
     <version>${gwtVersion}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-dev</artifactId> 
     <version>${gwtVersion}</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>2.5.6</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.ws</groupId> 
     <artifactId>spring-oxm-tiger</artifactId> 
     <version>1.5.8</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-web</artifactId> 
     <version>2.5.6</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-test</artifactId> 
     <version>2.5.6</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.poi</groupId> 
     <artifactId>poi</artifactId> 
     <version>3.6.full</version> 
    </dependency> 
    <dependency> 
     <groupId>axis</groupId> 
     <artifactId>axis</artifactId> 
     <version>1.2</version> 
    </dependency> 
    <dependency> 
     <groupId>axis</groupId> 
     <artifactId>axis-jaxrpc</artifactId> 
     <version>1.2</version> 
    </dependency> 
    <dependency> 
     <groupId>axis</groupId> 
     <artifactId>axis-wsdl4j</artifactId> 
     <version>1.2</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
     <version>1.1.1</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-discovery</groupId> 
     <artifactId>commons-discovery</artifactId> 
     <version>0.4</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.4</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.cxf</groupId> 
     <artifactId>cxf-rt-frontend-jaxws</artifactId> 
     <version>2.6.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.cxf</groupId> 
     <artifactId>cxf-rt-transports-http</artifactId> 
     <version>2.6.0</version> 
    </dependency> 
    <dependency> 
     <groupId>com.acn.acs.services</groupId> 
     <artifactId>SemiOnlineAcrtsService</artifactId> 
     <version>1.0</version> 
    </dependency> 
</dependencies> 

<build> 
    <!-- Generate compiled stuff in the folder used for developing mode --> 
    <outputDirectory>target/www/WEB-INF/classes</outputDirectory> 

    <plugins> 

     <!-- GWT Maven Plugin --> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>gwt-maven-plugin</artifactId> 
      <version>${gwtVersion}</version> 
      <!-- JS is only needed in the package phase, this speeds up testing --> 
      <executions> 
       <execution> 
        <phase>prepare-package</phase> 
        <goals> 
         <goal>compile</goal> 
        </goals> 
       </execution> 
      </executions> 
      <!-- Plugin configuration. There are many available options, see gwt-maven-plugin documentation at codehaus.org --> 
      <configuration> 
       <!-- URL that should be automatically opened in the GWT shell (gwt:run). --> 
       <runTarget>server.html</runTarget> 
       <!-- Location of the develop-mode web application structure (gwt:run). --> 
       <hostedWebapp>target/www</hostedWebapp> 
       <!-- Ask GWT to create the Story of Your Compile (SOYC) (gwt:compile) --> 
       <soyc>true</soyc> 
      </configuration> 
     </plugin> 

     <!-- Copy static web files before executing gwt:run --> 
     <plugin> 
      <artifactId>maven-resources-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>1</id> 
        <phase>compile</phase> 
        <goals> 
         <goal>copy-resources</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>target/www</outputDirectory> 
         <resources> 
          <resource> 
           <directory>src/main/webapp</directory> 
          </resource> 
         </resources> 
        </configuration> 
       </execution> 
       <execution> 
        <id>3</id> 
        <phase>compile</phase> 
        <goals> 
         <goal>copy-resources</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>target/www/WEB-INF/classes</outputDirectory> 
         <resources> 
          <resource> 
           <directory>src/main/resources</directory> 
          </resource> 
         </resources> 
        </configuration> 
       </execution> 

      </executions> 
     </plugin> 

     <!-- Delete gwt generated stuff --> 
     <plugin> 
      <artifactId>maven-clean-plugin</artifactId> 
      <configuration> 
       <filesets> 
        <fileset> 
         <directory>src/main/webapp/acrtsgwtserver</directory> 
        </fileset> 
        <fileset> 
         <directory>src/main/webapp/WEB-INF/classes</directory> 
        </fileset> 
        <fileset> 
         <directory>tomcat</directory> 
        </fileset> 
        <fileset> 
         <directory>www-test</directory> 
        </fileset> 
        <fileset> 
         <directory>.gwt-tmp</directory> 
        </fileset> 
       </filesets> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>install</phase> 
        <goals> 
         <goal>war</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
</project> 

請求你幫助我,讓我可以用它代替${user.home}/.m2/repository

本地資源庫

在此先感謝。

+0

答案有幫助嗎? – Adarsh

回答

0

settings.xml是Maven的配置文件。它可以在兩個級別指定:

  1. 用戶級別。此settings.xml文件爲單個用戶提供配置, ,通常在$ {user.home} /。m2/settings.xml中提供。

  2. Global Level。這個settings.xml文件爲一臺機器上的所有Maven 用戶提供配置(假設他們都使用相同的Maven 安裝)。它通常在 $ {maven.home} /conf/settings.xml中提供。

優先考慮用戶級別settings.xml。

只使用一個settings.xml。然後將元素<localRepository>的值更改爲所需的位置。我認爲應該完成這項工作。