2013-01-22 219 views
0

我正在使用maven構建我的項目。我想創建包含一些依賴項的組裝jar,所以我編寫了我的自定義組件描述符。Maven,Jar不包含主項目jar

的pom.xml

<plugin> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <configuration> 
     <archive> 
      <manifest> 
      <mainClass>com.guavus.exporter.Exporter</mainClass> 
      </manifest> 
     </archive> 
     <descriptors> 
      <descriptor>/Users/archit.thakur/Documents/Code_dev_cdn_mapreduce/exporter/src/main/assembly/configurator.xml</descriptor> 
      <!-- <descriptorRef>jar-with-dependencies</descriptorRef>  --> 
     </descriptors> 
     <finalName>Exporter-${project.version}</finalName> 
     <appendAssemblyId>false</appendAssemblyId> 
     </configuration> 
     <executions> 
     <execution> 
      <id>make-assembly</id> 
      <phase>package</phase> 
      <goals> 
      <goal>single</goal> 
      </goals> 
     </execution> 
     </executions> 
    </plugin> 
    <plugin> 
     <artifactId>maven-jar-plugin</artifactId> 
     <version>2.3.1</version> 
     <executions> 
     <execution> 
      <id>default-jar</id> 
      <phase>none</phase> 
     </execution> 
     </executions> 
    </plugin> 

裝配描述:

 <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2  http://maven.apache.org/xsd/assembly-1.1.2.xsd"> 
      <id>dep</id> 
      <formats> 
      <format>jar</format> 
      </formats> 
      <dependencySets> 
      <dependencySet> 
       <outputDirectory>${project.artifactId}</outputDirectory> 
       <unpack>true</unpack> 
       <useProjectArtifact>true</useProjectArtifact> 
       <includes> 
       <include>log4j:log4j</include> 
       <include>org.slf4j:slf4j-api</include> 
       <include>ch.qos.logback:logback-access</include> 
       <include>ch.qos.logback:logback-classic</include> 
       <include>ch.qos.logback:logback-core</include> 
       </includes> 
      </dependencySet> 
      </dependencySets> 
     </assembly> 

的問題是,現在它正在創建的jar只有具有相關罐子。而不是將我的代碼製作成jar,並將其包含在最終的jar中。

+0

爲什麼你需要在程序集描述符中使用「includes」?默認情況下,「dependencySet」包含所有依賴的jar。 –

+0

是的。但我不想包含所有的依賴關係。如果我不使用「」,我將不得不使用標籤「」來指定我在裝配jar中不需要的依賴項。 –

+0

你還試圖把你的項目放在「包含」內嗎? –

回答

1

嘗試使用Shade插件:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>1.2.2</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
        <configuration> 
         <transformers> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
           <mainClass>com.app.MyMainClass</mainClass> 
          </transformer> 
         </transformers> 
         <filters> 
          <filter> 
           <artifact>org.eclipse.swt.win32.win32:x86</artifact> 
           <excludes> 
            <exclude>META-INF/eclipse.inf</exclude> 
            <exclude>META-INF/ECLIPSE.RSA</exclude> 
            <exclude>META-INF/ECLIPSE.SF</exclude> 
           </excludes> 
          </filter> 
         </filters> 
        </configuration> 
       </execution> 
      </executions> 
      <configuration> 
       <encoding>${project.build.sourceEncoding}</encoding> 
      </configuration> 
     </plugin> 
    </plugins> 
    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
      <excludes> 
       <exclude>**/*.java</exclude> 
      </excludes> 
     </resource> 

    </resources> 
</build> 
0
<fileset>...my classes... </fileset> 

添加標籤的組件配置器/描述符解決了這個問題。

由於此評論:

也許嘗試添加一個文件集在目標/ classes目錄的一切嗎? (不記得POM變量引用非常抱歉...) - Charlie 1月22日7:21

相關問題