2013-07-16 11 views
11

मैं निर्भरता के साथ निष्पादन योग्य जार बनाने के लिए बहुत सारे समाधान पढ़ता हूं (मेवेन छाया प्लगइन, मैवेन निर्भरता प्लगइन, मेवेन असेंबली प्लगइन) और ये सभी प्लगइन्स अप्रत्याशित निर्भरता जार और निष्पादन योग्य जार में उन्हें दोबारा दोहराएं। निष्पादन योग्य जार में अनपॅक किए गए निर्भरता जार पैक करने वाली एकमात्र प्लगइन एक जार प्लगइन है लेकिन यह प्लगइन निष्पादन योग्य जार में अपना धावक कोड जोड़ता है।निर्भरता के साथ निष्पादन योग्य जार बनाने के लिए मेवेन प्लगइन अनपॅक किए गए (जार के साथ जार)

├─executable.jar 
├──lib/ 
├───dependency1.jar 
├───dependency2.jar 
. 
. 
. 

और उस समाधान काम करने के लिए:

वहाँ इस तरह जार बनाने के लिए किसी भी समाधान है।

+0

आप की संभावना एक कस्टम वर्ग-लोडर की आवश्यकता होगी कक्षाएं एक संग्रह के अंदर जार में बंडल किए गए लोड करने के लिए तो अंतिम समाधान की तरह दिखाई देगा। क्या आपने [एक जार] (http://one-jar.sourceforge.net/) पर एक नज़र डाली है? –

उत्तर

0
<plugins> 
      <plugin> 
       <artifactId>maven-eclipse-plugin</artifactId> 
       <version>2.9</version> 
       <configuration> 
        <additionalProjectnatures> 
         <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> 
        </additionalProjectnatures> 
        <additionalBuildcommands> 
         <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand> 
        </additionalBuildcommands> 
        <downloadSources>true</downloadSources> 
        <downloadJavadocs>true</downloadJavadocs> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.5.1</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <compilerArgument>-Xlint:all</compilerArgument> 
        <showWarnings>true</showWarnings> 
        <showDeprecation>true</showDeprecation> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.2.1</version> 
       <configuration> 
        <mainClass>org.test.int1.Main</mainClass> 
       </configuration> 
      </plugin> 
     </plugins> 
+0

आप अपने pom.xml में yhis जोड़ सकते हैं। इसके बाद आप निष्पादन योग्य जार प्राप्त कर सकते हैं – Ritesh

1

सबसे आम तरीका है जो आप एक तरह से आप

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <configuration> 
     <archive> 
       <manifest> 
        <mainClass>com.somewhere.Main</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> 

जरूरत है इसके अलावा, आप विन्यास

<configuration> 
    <appendAssemblyId>false</appendAssemblyId> 
    <descriptors> 
     <descriptor>src/main/assembly/assembly.xml</descriptor> 
    </descriptors> 
</configuration> 

के लिए विधानसभा वर्णनकर्ता निर्दिष्ट कर सकते हैं में पैकेजिंग कॉन्फ़िगर करने की अनुमति देगा विधानसभा प्लगइन का उपयोग करने के लिए है और assembly.xml खुद

<assembly> 
    <id>assembly</id> 
    <formats> 
     <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <fileSets> 
     <fileSet> 
      <directory>${project.build.outputDirectory}</directory> 
      <outputDirectory>/</outputDirectory> 
     </fileSet> 
    </fileSets> 
</assembly> 

विधानसभा वर्णनकर्ता भी निर्भरता अनुभाग हो सकते हैं:

<!-- lib --> 
<dependencySets> 
    <dependencySet> 
     <outputDirectory>lib</outputDirectory> 
    </dependencySet> 
</dependencySets> 

जहां तक ​​मैं समझता हूँ कि आपने पिछले एक के लिए देख रहे हैं। चूंकि इसमें बिना किसी संशोधन के असेंबली में जार फाइलें शामिल हैं।

<assembly> 
    <id>assembly</id> 
    <formats> 
     <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <!-- lib --> 
    <dependencySets> 
     <dependencySet> 
      <outputDirectory>lib</outputDirectory> 
     </dependencySet> 
    </dependencySets> 
</assembly> 

और पोम हिस्सा:

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <configuration> 
     <appendAssemblyId>false</appendAssemblyId> 
     <descriptors> 
      <descriptor>src/main/assembly/assembly.xml</descriptor> 
     </descriptors> 
    </configuration> 
    <executions> 
      <execution> 
       <id>make-assembly</id> 
       <phase>package</phase> 
       <goals> 
        <goal>single</goal> 
       </goals> 
     </execution> 
    </executions> 
</plugin> 
संबंधित मुद्दे