2015-01-20 85 views
0

我有一個模塊,我使用maven-assembly-plugin創建一個可執行的jar與依賴關係。當我運行安裝,插件會預先考慮罐子名之前的項目(「附近」)的名稱和所有jar內容,即:maven-assembly-plugin預先考慮類路徑

$ jar -tvf vicinity-confirm-assets.jar | more 
    0 Tue Jan 20 17:18:10 EST 2015 META-INF/ 
    213 Tue Jan 20 17:18:08 EST 2015 META-INF/MANIFEST.MF 
    0 Tue Jan 20 17:18:10 EST 2015 vicinity/ 
    0 Thu Nov 13 20:52:16 EST 2014 vicinity/META-INF/ 
    134 Thu Nov 13 20:52:14 EST 2014 vicinity/META-INF/MANIFEST.MF 
    0 Thu Nov 13 20:52:06 EST 2014 vicinity/org/ 
    0 Thu Nov 13 20:52:10 EST 2014 vicinity/org/boon/ 
    0 Thu Nov 13 20:52:10 EST 2014 vicinity/org/boon/cache/ 
    0 Thu Nov 13 20:52:10 EST 2014 vicinity/org/boon/collections/ 
    0 Thu Nov 13 20:52:10 EST 2014 vicinity/org/boon/concurrent/ 
    ... 
    0 Tue Jan 20 17:17:50 EST 2015 vicinity/META-INF/maven/com.thingy.webapp/confirmassets/ 
    2208 Tue Jan 20 17:17:44 EST 2015 vicinity/META-INF/maven/com.thingy.webapp/confirmassets/pom.xml 
    127 Tue Jan 20 16:25:22 EST 2015 vicinity/META-INF/maven/com.thingy.webapp/confirmassets/pom.properties 

這裏是插件的xml:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.4</version> 
      <configuration> 
       <archive> 
        <manifest> 
         <mainClass>com.thingy.webapp.confirmassets.ToolbarResourcesUrlTester</mainClass> 
        </manifest> 
       </archive> 
       <descriptors> 
        <descriptor>src/main/resources/dist.xml</descriptor> 
       </descriptors> 
      </configuration> 
      <executions> 
       <execution> 
        <id>make-assembly</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

這裏是dist.xml:

<?xml version='1.0' encoding='UTF-8'?> 
<assembly> 
    <id>confirm-assets</id> 
    <formats> 
     <format>jar</format> 
    </formats> 

    <dependencySets> 
     <dependencySet> 
      <scope>runtime</scope> 
      <unpack>true</unpack> 
      <unpackOptions> 
       <excludes> 
        <exclude>**/LICENSE*</exclude> 
        <exclude>**/README*</exclude> 
       </excludes> 
      </unpackOptions> 
     </dependencySet> 
    </dependencySets> 

    <fileSets> 
     <fileSet> 
      <directory>${project.build.outputDirectory}</directory> 
      <outputDirectory>/</outputDirectory> 
     </fileSet> 
     <fileSet> 
      <directory>src/main/resources/META-INF/services</directory> 
      <outputDirectory>META-INF/services</outputDirectory> 
     </fileSet> 
    </fileSets>  
</assembly> 

ETA:在 「附近」 前面加上從父POM的<build><finalName>vicinity</finalName>...</build>到來。但是將這個前置到jar中包含的每個文件和依賴項是沒有意義的。我試着用模塊的pom中空的<finalName></finalName>標籤覆蓋,但是後來我得到了一個破折號。我如何擺脫這一切,只是在罐子裏包含正確命名的內容?

ALSO:我遇到的問題是,當我嘗試在命令行中運行我的主類,我得到:

$ java -jar vicinity-confirm-assets.jar 
Error: Could not find or load main class com.thingy.webapp.confirmassets.ToolbarResourcesUrlTester 

此外,還有兩個MANIFEST.MF文件。

$ jar -tvf vicinity-confirm-assets.jar | grep MANI 
    213 Tue Jan 20 18:07:26 EST 2015 META-INF/MANIFEST.MF 
    134 Thu Nov 13 20:52:14 EST 2014 vicinity/META-INF/MANIFEST.MF 

第一招:

Manifest-Version: 1.0 
Built-By: barclaydunn 
Build-Jdk: 1.6.0_65 
Created-By: Apache Maven 3.1.1 
Main-Class: com.thingy.webapp.confirmassets.ToolbarResourcesUrlTest 
er 
Archiver-Version: Plexus Archiver 

第二:

Manifest-Version: 1.0 
Built-By: slandelle 
Build-Jdk: 1.7.0_65 
Created-By: Apache Maven 3.2.2 
Archiver-Version: Plexus Archiver 

我猜有兩個原因,而預謀從何而來,事實證明這是一個孩子模塊。第二個來自父母,我猜測。

我想做一些不能/不應該做的事嗎?

回答

0

萬一別人有這個問題,我發現,你可以控制的基本目錄是否包含在dist.xml <includeBaseDirectory>false</includeBaseDirectory>

<?xml version='1.0' encoding='UTF-8'?> 
<assembly> 
    <id>confirm-assets</id> 
    <formats> 
     <format>jar</format> 
    </formats> 

    <includeBaseDirectory>false</includeBaseDirectory> 
    ... 

欲瞭解更多信息,請參閱http://maven.apache.org/plugins/maven-assembly-plugin/advanced-descriptor-topics.html#Using_an_Alternative_Assembly_Base_Directory