2011-09-28 74 views
0

我有從多個maven模塊構建單個可執行jar的問題。 所以這裏的情況:我有三個maven模塊:應用程序 - >持久性 - >域。我也有父pom.xml。我加入到這一父POM行家組件插件:從多個maven模塊構建可執行jar

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <configuration> 
     <archive> 
      <manifest> 
       <mainClass>com.toys.app.Service</mainClass> 
      </manifest> 
     </archive> 
     <descriptorRefs> 
      <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
    </configuration> 
</plugin> 

因此,當我從命令行在父POM目錄(其含有parent.pom和應用程式,持久性和域行家模塊)類型的命令:MVN組件:組件 它給了我一個錯誤:

[INFO] ------------------------------------------------------------------------ 
[INFO] Building persistence 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (default-cli) @ persistence --- 
[INFO] ------------------------------------------------------------------------ 
[INFO] Reactor Summary: 
[INFO] 
[INFO] parent ..................................... SUCCESS [3.147s] 
[INFO] domain ............................................ SUCCESS [4.765s] 
[INFO] persistence ....................................... FAILURE [0.570s] 
[INFO] app ............................................... SKIPPED 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 9.287s 
[INFO] Finished at: Wed Sep 28 12:30:26 CEST 2011 
[INFO] Final Memory: 6M/81M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (default-cli) on project persistence: Failed to create assembly: Failed to resolve dependencies for project: com.toys:persistence:jar:1.0-SNAPSHOT: Missing: 
[ERROR] ---------- 
[ERROR] 1) com.toys:domain:jar:1.0-SNAPSHOT 
[ERROR] 
[ERROR] Try downloading the file manually from the project website. 
[ERROR] 
[ERROR] Then, install it using the command: 
[ERROR] mvn install:install-file -DgroupId=com.toys -DartifactId=domain -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file 
[ERROR] 
[ERROR] Alternatively, if you host your own repository you can deploy the file there: 
[ERROR] mvn deploy:deploy-file -DgroupId=com.toys -DartifactId=domain -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id] 
[ERROR] 
[ERROR] Path to dependency: 
[ERROR] 1) com.toys:persistence:jar:1.0-SNAPSHOT 
[ERROR] 2) com.toys:domain:jar:1.0-SNAPSHOT 
[ERROR] 
[ERROR] ---------- 
[ERROR] 1 required artifact is missing. 
[ERROR] 
[ERROR] for artifact: 
[ERROR] com.toys:persistence:jar:1.0-SNAPSHOT 
[ERROR] 
[ERROR] from the specified remote repositories: 
[ERROR] central (http://repo1.maven.org/maven2, releases=true, snapshots=false) 
[ERROR] -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command 
[ERROR] mvn <goals> -rf :persistence 

每隔Maven的生命週期正常工作!誰能幫我?

+0

那些依賴項的範圍是什麼? – Thomas

+0

默認情況下,這是「編譯」 –

回答

0

嘗試添加執行階段:

 <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
       <archive> 
        <manifest> 
        <mainClass>com.toys.app.Service</mainClass> 
        </manifest> 
       </archive>    
       <descriptorRef>jar-with-dependencies</descriptorRef>     
      </configuration> 
      <executions> 
       <execution> 
        <id>make-jar-with-dependencies</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
+0

這是工作,但是當我提取這個罐子,沒有包和類寫我寫的! –

+0

你如何運行這個構建?首先:嘗試在每個子模塊上運行「安裝」。然後在所需模塊上運行'包'目標。 –

+0

我試圖在每個模塊上運行「install」,域模塊成功完成,但依賴於域模塊的持久性模塊給了我一個錯誤:** [ERROR]無法執行項目持久性目標:無法解析依賴關係for project com.toys:persistence:jar:1.0-SNAPSHOT:無法爲[com.toys:domain:jar:1.0-SNAPSHOT(compile),org.springframework:spring-tx:jar:3.0.5.RELEASE收集依賴關係(編譯),...]:無法讀取com.toys:domain:jar:1.0-SNAPSHOT的工件描述符:無法找到工件com.toys:parent:pom:1.0-SNAPSHOT - > [Help 1] ** –

0

我建議你添加在同一水平上爲您的應用程序,持久性,領域工程項目「分配」。

<project> 

    <artifactId>distribution</artifactId> 
    <packaging>pom</packaging> 

    <parent> 
    ... 
    </parent> 

    <dependencies> 
    <dependency> 
     <groupId>${project.groupId}</groupId> 
     <artifactId>app</artifactId> 
     <version>${project.version}</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>${project.groupId}</groupId> 
     <artifactId>persistence</artifactId> 
     <version>${project.version}</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>${project.groupId}</groupId> 
     <artifactId>domain</artifactId> 
     <version>${project.version}</version> 
     <scope>runtime</scope> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
      <archive> 
       <manifest> 
       <mainClass>com.toys.app.Service</mainClass> 
       </manifest> 
      </archive>    
      <descriptorRef>jar-with-dependencies</descriptorRef>     
      </configuration> 
      <executions> 
      <execution> 
       <id>make-jar-with-dependencies</id> 
       <phase>package</phase> 
       <goals> 
       <goal>single</goal> 
       </goals> 
      </execution> 
      </executions> 
     <plugin> 
    </plugins> 
    </build> 

</project> 

我在嘗試在移動到自己的項目後創建分佈在反應器POM中時遇到了類似的問題 - 沒有頭痛。

此外,不要忘記添加'分配'模塊到反應堆項目。