Maven不会复制依赖项

时间:2013-11-12 21:26:38

标签: maven maven-plugin

我正在使用maven-jar-plugin和maven-dependency-plugin,期望依赖的jar会被复制到我的jar文件中的lib文件夹中,但这不会发生。 (然而jar被复制到jar之外的target / lib但从未复制到jar中。并且依赖关系被添加到清单中的类路径中)。我在这里弄错了吗?谢谢你的帮助。

 <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>abc</groupId>
   <artifactId>SendXmlJms</artifactId>
   <packaging>jar</packaging>
   <version>1.0</version>
   <name>SendXmlJms</name>
   <description>send jms message</description>
   <build>
    <sourceDirectory>src</sourceDirectory>
     <resources>
       <resource>
        <directory>src</directory>
         <excludes>
          <exclude>**/*.java</exclude>
         </excludes>
      </resource>
     </resources>

    <plugins>
       <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
          <source>1.6</source>
          <target>1.6</target>
          </configuration>
       </plugin>
       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <classpathPrefix>lib</classpathPrefix>
              <mainClass>SendJms</mainClass>
            </manifest>
          </archive>
         </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
           <version>2.1</version>
          <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
           </goals>
           <configuration>
               <includeGroupIds>org.springframework</includeGroupIds>
               <outputDirectory>${project.build.directory}/lib</outputDirectory>
               <overWriteReleases>false</overWriteReleases>
               <overWriteSnapshots>false</overWriteSnapshots>
               <overWriteIfNewer>true</overWriteIfNewer>
           </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>

  </build>

  <repositories>
    <repository>
      <id>java.net-m2</id>
       <name>java.net - Maven 2</name>
        <url>https://repository.jboss.org/nexus/content/repositories/java.net-m2</url>
     </repository>
   </repositories>  

   <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 -->
    <org.springframework.version>3.2.4.RELEASE</org.springframework.version>

    <!-- Hibernate / JPA -->
    <hibernate.version>4.2.1.Final</hibernate.version>

    <!-- Logging -->
    <logback.version>1.0.13</logback.version>
    <slf4j.version>1.7.5</slf4j.version>

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

</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Logging with SLF4J & LogBack -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${logback.version}</version>
        <scope>runtime</scope>
    </dependency>

    <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.5.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.2.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jms</artifactId>
        <version>3.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.6</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
<dependency>
        <groupId>com.sun.messaging.mq</groupId>
        <artifactId>fscontext</artifactId>
        <version>4.2</version>
    </dependency>
   <dependency>
        <groupId>jboss</groupId>
        <artifactId>jboss-j2ee</artifactId>
        <version>3.2.1</version>
  </dependency>
    <!-- Test Artifacts -->
    <dependency>
          <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
       </dependencies>  
     </project>

1 个答案:

答案 0 :(得分:0)

我遇到问题的jar包含了一个模块,该模块将在另一个后来的maven构建中使用。我稍后在具有系统范围的本地文件系统上引用它。系统范围工件不会被复制到运行时jar。

不是使用程序集插件,而是一个更简单的解决方案(以及maven项目文档推荐的解决方案)是在本地安装组件模块,然后再引用它。

我使用了exec-maven-plugin在我的组件构建结束时执行此操作。