2011-07-18 26 views
11

在我的Khatami項目中,我使用maven來管理編譯並將結果打包爲可運行的工件:頂層的可執行shell腳本,bin/包含可執行文件罐子及其相關的罐子。請看我的意思是heremaven-assembly-plugin MojoExecutionException與依賴項集作爲outputDirectory

以供參考,在這裏是哈塔米pom.xml的突出部分:

 <plugin> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <configuration> 
      <descriptors> 
      <descriptor>src/main/assembly/src.xml</descriptor> 
      </descriptors> 
      <archive> 
      <manifest> 
       <mainClass>${project.groupId}.Main</mainClass> 
      </manifest> 
      </archive> 
      <descriptorRefs> 
      <descriptorRef>jar-with-dependencies</descriptorRef> 
      </descriptorRefs> 
     </configuration> 
     </plugin> 

和全src/main/assembly/src.xml

<assembly> 
    <id>dist</id> 
    <formats> 
    <format>tar.gz</format> 
    </formats> 
    <dependencySets> 
    <dependencySet> 
     <outputDirectory>bin</outputDirectory> 
    </dependencySet> 
    </dependencySets> 
    <fileSets> 
    <fileSet> 
     <directory>src/main/assembly</directory> 
     <outputDirectory>/</outputDirectory> 
     <includes> 
     <include>khatami</include> 
     </includes> 
     <fileMode>744</fileMode> 
     <lineEnding>unix</lineEnding> 
     <filtered>true</filtered> 
    </fileSet> 
    </fileSets> 
</assembly> 

和編譯嘗試:

$ mvn clean compile assembly:single 
[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building khatami 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ khatami --- 
[INFO] Deleting /home/blt/projects/com/carepilot/repos/khatami/target 
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ khatami --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] skip non existing resourceDirectory /home/blt/projects/com/carepilot/repos/khatami/src/main/resources 
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ khatami --- 
[INFO] Compiling 1 source file to /home/blt/projects/com/carepilot/repos/khatami/target/classes 
[INFO] 
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (default-cli) @ khatami --- 
[INFO] Reading assembly descriptor: src/main/assembly/src.xml 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 3.721s 
[INFO] Finished at: Mon Jul 18 13:58:30 EDT 2011 
[INFO] Final Memory: 8M/123M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (default-cli) on project khatami: Failed to create assembly: Error adding file 'com.carepilot.khatami:khatami:jar:1.0-SNAPSHOT' to archive: /home/blt/projects/com/carepilot/repos/khatami/target/classes isn't a file. -> [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 

哪裏有過錯的是我?

+1

你是如何運行你的maven構建?從命令行或在IDE內> –

+0

命令行。最後的代碼清單包含相關的行,以''''''開頭。 – troutwine

+0

你有沒有在eclipse中使用這個項目,並使用一些插件將它導入到eclipse環境中。這看起來像一些maven配置問題。我遇到過這種問題,並將其跟蹤到我的m2eclipse插件。 (順便說一句,s ** ks) –

回答

14

的錯誤信息的相關部分是

Error adding file 'com.carepilot.khatami:khatami:jar:1.0-SNAPSHOT' to archive: 
/home/blt/projects/com/carepilot/repos/khatami/target/classes isn't a file. 

它期待一個文件,因爲package目標不是clean運行後無法找到它。

如果你做mvn clean compile package assembly:single它會成功構建。

我會將assembly:single目標添加到package階段,這樣它就會自動生成。

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <executions> 
    <execution> 
     <phase>package</phase> 
     <goals> 
     <goal>single</goal> 
     </goals> 
     <configuration> 
     <descriptors> 
      <descriptor>src/main/assembly/src.xml</descriptor> 
     </descriptors> 
     <archive> 
      <manifest> 
      <mainClass>${project.groupId}.Main</mainClass> 
      </manifest> 
     </archive> 
     <descriptorRefs> 
      <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 

對上述配置的更改可以發出。

mvn clean package 

and the assembly:single goal will be automatically automatically。

更好的方法可能是使用maven-shade-plugin而不是手動完成此操作。

3

您的問題:

Error adding file 'com.carepilot.khatami:khatami:jar:1.0-SNAPSHOT' to archive: 
/home/blt/projects/com/carepilot/repos/khatami/target/classes isn't a file. 

造成,因爲該項目神器(com.carepilot.khatami:哈塔米:罐子:1.0-SNAPSHOT)尚未打包呢,不過是程序集<dependencySet>的一部分。您可以將<useProjectArtifact>false</useProjectArtifact>添加到您的<dependencySet>以解決問題。

如果您需要包含在程序集中的項目的類文件,則可以使用<fileSet>來包含目錄target/classes

例如:

<assembly> 
    <id>dist</id> 
    <formats> 
    <format>tar.gz</format> 
    </formats> 
    <dependencySets> 
    <dependencySet> 
     <useProjectArtifact>false</useProjectArtifact> 
     <outputDirectory>bin</outputDirectory> 
    </dependencySet> 
    </dependencySets> 
    <fileSets> 
    <fileSet> 
     <directory>src/main/assembly</directory> 
     <outputDirectory>/</outputDirectory> 
     <includes> 
     <include>khatami</include> 
     </includes> 
     <fileMode>744</fileMode> 
     <lineEnding>unix</lineEnding> 
     <filtered>true</filtered> 
    </fileSet> 
    </fileSets> 
</assembly> 

另一種選擇是packaging之後將組件連接到一個相。