2009-10-05 15 views
27

मेरे पास एक प्रोजेक्ट है जिससे मैं एक वितरण ज़िप फ़ाइल बनाने की कोशिश कर रहा हूं, जिसमें मेरे जावा प्रोजेक्ट की निर्भरताओं के साथ एक निष्पादन योग्य जार शामिल है (अन्य फाइलों के साथ)।मेवेन-असेंबली प्लगइन - नेस्टेड असेंबली कैसे बनाएं

तो मैं इन सबसे छुटकारा पाना इस तरह दिखना चाहते हैं:

-wiki-search-1.0.0-dist.zip 
    -wiki-search.bat 
    -wiki-search-help.html 
    -wiki-search-1.0.0-jar-with-dependencies.jar 
     -jar content... 

मैं विधानसभा प्लगइन का उपयोग कर रहा है, और पूर्वनिर्धारित वर्णनकर्ता "जार-साथ-निर्भरता" मेरे निष्पादन योग्य जार फ़ाइल बनाने के लिए।

मैं अपने पोम में एक अलग असेंबली प्लगइन प्रविष्टि निर्दिष्ट कर रहा हूं, वितरित ज़िप फ़ाइल को आजमाने और बनाने के लिए कस्टम डिस्क्रिप्टर का संदर्भ देता हूं।

तो मेरी पोम का हिस्सा इस तरह दिखता है:

<plugin> 
<artifactId>maven-assembly-plugin</artifactId> 
<configuration> 
    <descriptorRefs> 
    <descriptorRef>jar-with-dependencies</descriptorRef> 
    </descriptorRefs> 
    <archive> 
    <manifest> 
    <mainClass>quicksearch.QuickSearchApp</mainClass> 
    </manifest> 
    </archive> 
</configuration> 
<executions> 
    <execution> 
    <id>make-assembly</id> 
    <phase>package</phase> 
    <goals> 
    <goal>attached</goal> 
    </goals> 
    </execution> 
</executions> 
</plugin> 
<plugin> 
<artifactId>maven-assembly-plugin</artifactId> 
<configuration> 
    <descriptors> 
    <descriptor>src/main/assembly/dist.xml</descriptor> 
    </descriptors> 
</configuration> 
<executions> 
    <execution> 
    <id>make-assembly</id> 
    <phase>package</phase> 
    <goals> 
    <goal>attached</goal> 
    </goals> 
    </execution> 
</executions> 
</plugin> 

और अपने कस्टम वर्णनकर्ता इस तरह दिखता है:

<assembly> 
    <id>dist</id> 
    <formats> 
    <format>tar.gz</format> 
    <format>tar.bz2</format> 
    <format>zip</format> 
    </formats> 
    <fileSets> 
    <fileSet> 
     <includes> 
     <include>${project.basedir}/target/wiki-search-0.0.1-SNAPSHOT-jar-with-dependencies.jar</include> 
     </includes> 
     <outputDirectory>.</outputDirectory> 
    </fileSet> 
    <fileSet> 
     <directory>${project.basedir}/src/main/etc</directory> 
     <includes> 
     <include>*</include> 
     </includes> 
    <outputDirectory></outputDirectory> 
    </fileSet> 
    </fileSets> 
</assembly> 

सब कुछ ठीक काम करता है। जार-निर्भरताएं बनाई जा रही हैं। मेरी डिस्ट ज़िप फ़ाइल बनाई जा रही है। लेकिन dist ज़िप फ़ाइल में जार-निर्भर-निर्भरता फ़ाइल नहीं है।

उत्तर

43

आपकी मौजूदा कॉन्फ़िगरेशन के साथ, असेंबली प्लगइन के लिए आपके दो अलग कॉन्फ़िगरेशन विलय किए जाएंगे, और कॉन्फ़िगरेशन भी विलय हो जाएंगे।

अपना लक्ष्य प्राप्त करने के लिए आपको एक ही असेंबली-प्लगइन कॉन्फ़िगरेशन को कई नेस्टेड निष्पादन के साथ परिभाषित करना चाहिए, फिर उसके अंदर प्रत्येक निष्पादन के लिए कॉन्फ़िगरेशन को परिभाषित करना चाहिए। असेंबली प्लगइन क्रमशः प्रत्येक असेंबली को निष्पादित करेगा, इसलिए jar-with-dependencies जार dist जार में शामिल करने के लिए उपलब्ध होगा। यह भी ध्यान दें कि attached लक्ष्य को single लक्ष्य के पक्ष में बहिष्कृत किया गया है।

यह भी ध्यान रखें कि असेंबली में पथ रूट के सापेक्ष हैं, और एक विशेष फ़ाइल को शामिल करने के लिए आपको <filesets> तत्व के बजाय <files> तत्व का उपयोग करना चाहिए। आप इसे बदलने के लिए कम नाजुक बनाने के लिए असेंबली में गुण भी निर्दिष्ट कर सकते हैं।

पुनर्व्यवस्थित विन्यास और विधानसभा नीचे करना चाहिए कि आप क्या कर रहे हैं के बाद:

विधानसभा वर्णनकर्ता:

<assembly> 
    <id>dist</id> 
    <formats> 
    <format>tar.gz</format> 
    <format>tar.bz2</format> 
    <format>zip</format> 
    </formats> 
    <files> 
    <file> 
     <source> 
     target/${project.artifactId}-${project.version}-jar-with-dependencies.jar 
     </source> 
     <outputDirectory>/</outputDirectory> 
    </file> 
    </files> 
    <fileSets> 
    <fileSet> 
     <directory>${project.basedir}/src/main/resources</directory> 
     <includes> 
     <include>*</include> 
     </includes> 
    <outputDirectory>/</outputDirectory> 
    </fileSet> 
    </fileSets> 
</assembly> 

विधानसभा प्लगइन:

<plugin> 
<artifactId>maven-assembly-plugin</artifactId> 
<executions> 
    <execution> 
    <id>jar-with-dependencies</id> 
    <phase>package</phase> 
    <goals> 
    <goal>single</goal> 
    </goals> 
    <configuration> 
    <descriptorRefs> 
    <descriptorRef>jar-with-dependencies</descriptorRef> 
    </descriptorRefs> 
    <archive> 
    <manifest> 
     <mainClass>quicksearch.QuickSearchApp</mainClass> 
    </manifest> 
    </archive> 
    </configuration> 
    </execution> 
    <execution> 
    <id>dist</id> 
    <phase>package</phase> 
    <goals> 
    <goal>single</goal> 
    </goals> 
    <configuration> 
    <descriptors> 
    <descriptor>src/main/assembly/dist.xml</descriptor> 
    </descriptors> 
    </configuration> 
    </execution> 
</executions> 
</plugin> 
+3

+1 बहुत अच्छी और विस्तृत जवाब –

+0

लीजेंड । पहली बार काम किया। चीयर्स। – Ben

+0

धन्यवाद! क्या डिफ़ॉल्ट जीवन चक्र में निष्पादन को संलग्न किए बिना इसे प्राप्त करने का कोई तरीका है? बस 'चरण' और 'लक्ष्यों' तत्वों को छोड़कर मेरे लिए काम नहीं किया। –

0

आपके पास असेंबली प्लग-इन के लिए दो अलग-अलग कॉन्फ़िगरेशन हैं, और आप उन्हें क्रम में चलाने के लिए चाहते हैं (ज़िप से पहले जार), लेकिन मुझे नहीं लगता कि मैवेन का यह हल होता है कि यह कैसे हल किया जाएगा। मेरा अनुमान है कि ज़िप फ़ाइल जेएआर फ़ाइल से पहले उत्पन्न की जा रही है।

भले ही यह मामला न हो, मैं सुझाव दूंगा कि आप प्रति आर्टिफैक्ट एक मॉड्यूल बनाएं। जेएआर असेंबली को अपने मॉड्यूल में ले जाएं और अब ज़िप-केवल मॉड्यूल इस पर निर्भर करता है। इस तरह मेवेन का निर्भरता आदेश संकल्प क्रमशः उन्हें ला सकता है और बना सकता है।

संबंधित मुद्दे