2015-10-21 68 views
1

依賴條件這個問題公頃sbeen問,但沒有解決方案的工作對我來說這樣:行家複製不工作

我想複製我的瓶子,其通過在pom.xml中的生成依賴標籤規定:

<dependency> 
... 
</dependency> 

到像目標/ lib中的一個文件夾

的pom.xml:

<build> 
    <defaultGoal>install</defaultGoal> 
    <directory>${basedir}/target</directory> 
    <finalName>${project.artifactId}-${project.version}</finalName> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>com.googlecode.addjars-maven-plugin</groupId> 
       <artifactId>addjars-maven-plugin</artifactId> 
       <version>1.0.5</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>add-jars</goal> 
         </goals> 
         <configuration> 
          <resources> 
           <resource> 
            <directory>${project.build.directory}/my-repo</directory> 
           </resource> 
          </resources> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <configuration> 
        <archive> 
         <manifest> 
          <classpathPrefix>lib/</classpathPrefix> 
          <addClasspath>true</addClasspath> 
          <mainClass>Swapper</mainClass> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.10</version> 
       <executions> 
        <execution> 
         <id>copy-dependencies</id> 
         <phase>package</phase> 
         <goals> 
          <goal>copy-dependencies</goal> 
         </goals> 
         <configuration> 
          <includeScope>runtime</includeScope> 
          <outputDirectory>${project.build.directory}/lib/</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

就像我說的,沒有任何東西被複制。但根據該門戶上的一些Q & A,它應該可以工作。

任何想法?

+0

什麼Maven目標,你運行?例如'mvn乾淨安裝'? – rmlan

+0

我試過很多的組合,MVN全新安裝,MVN包,但沒有人trigggred複製過程 – Gobliins

+0

你能不能給你所要完成的提示?創建安裝/分發包? – khmarbaise

回答

5

你在你<pluginManagement>節宣告你的插件。這是一切都很好,但如果他們想執行需要聲明他們<pluginManagement>節之外:在你認爲的<dependencyManagement>以同樣的方式

<build> 
    <pluginManagement> 
    ... 
    </pluginManagement> 
    <plugins> 
    <plugin> 
    <artifactId>addjars-maven-plugin</artifactId> 
    </plugin> 
    <plugin> 
    <artifactId>maven-jar-plugin</artifactId> 
    </plugin> 
    <plugin> 
    <artifactId>maven-dependency-plugin</artifactId> 
    </plugin> 
    </plugins> 
</build> 

,想出<pluginManagement>,但對於插件。

+1

是的,這是問題,thx。 – Gobliins

+0

一位智者曾經說過:「在你認爲的,但對於插件以同樣的方式思考的」。 – kongshem

0

嘗試更換:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-jar-plugin</artifactId> 
    <configuration> 
     <archive> 
      <manifest> 
       <classpathPrefix>lib/</classpathPrefix> 
       <addClasspath>true</addClasspath> 
       <mainClass>Swapper</mainClass> 
      </manifest> 
     </archive> 
    </configuration> 
</plugin> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <version>2.10</version> 
    <executions> 
     <execution> 
      <id>copy-dependencies</id> 
      <phase>package</phase> 
      <goals> 
       <goal>copy-dependencies</goal> 
      </goals> 
      <configuration> 
       <includeScope>runtime</includeScope> 
       <outputDirectory>${project.build.directory}/lib/</outputDirectory> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

通過此:

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
      <outputDirectory>${project.build.directory}/lib/</outputDirectory> 
       <archive> 
        <manifest> 
         <mainClass>Swapper</mainClass> 
        </manifest> 
       </archive> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
      </configuration> 
      <executions> 
       <execution> 
        <id>make-assembly</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
+0

嗨,奇怪的是,這個解決方案我得到了jar錯誤中缺少的主要屬性清單(用mvn install,mvn package測試) – Gobliins

+0

in Swapper add your package mainClass> com.company.Swapper –

+0

嗯,我的主類是從maven(src/main/java)的默認文件夾默認包 – Gobliins