2009-06-09 11 views
8

मैं मैर-इन-निर्भरता बनाने के लिए मेवेन 2 असेंबली प्लग-इन का उपयोग कर रहा हूं और निष्पादन योग्य JAR फ़ाइल बना रहा हूं। मेरी असेंबली में वसंत, और सीएक्सएफ पुस्तकालय शामिल है।मेवेन 2 असेंबली प्लगइन कुछ मेटा-आईएनएफ फाइलें

सीएक्सएफ में मेटा-आईएनएफ फाइलों की प्रतियां spring.schemas और spring.handlers शामिल हैं जो वसंत-2.5.4 जार से समान फ़ाइलों को क्लॉबरिंग करते हैं।

हाथ से, मैं उन दो फ़ाइलों को जार-निर्भरता के भीतर अपडेट कर सकता हूं।

जो मैं खोज रहा हूं वह मेवेन पीओएम में उन दो फ़ाइलों के सही संस्करण को पाने के लिए असेंबली प्लग-इन को निर्देशित करने का कोई तरीका है।

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

इस उदाहरण में एक कस्टम असेंबली डिस्क्रिप्टर मेरी एकमात्र आशा बना रहा है?

+0

एक ही बात "spring.tooling" फाइलों के साथ होता है, लेकिन उनके नाम से मेरा अनुमान है कि वे क्रम में इस्तेमाल किया नहीं कर रहे हैं। –

उत्तर

6

किसी कारण से मोजो और अन्य सुझाव देने वाले समाधान अभी भी मेरे लिए काम नहीं करते हैं।मैंने अपना कस्टम spring.handlers और spring.schemas फ़ाइलों को बनाया है और उन्हें src/main/resources/META-INF के अंतर्गत रखा है। हालांकि, unpackOptions का उपयोग करते समय मेरी फाइलें भी शामिल नहीं हैं। जब मैं unpackOptions का उपयोग नहीं करता हूं तो मेरी फ़ाइलें जार में नहीं हैं।

जो मैंने समाप्त किया वह सीधे फाइलों का संदर्भ देना है। अंततः मेरी फाइलें जार में डाल दीं।

<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"> 
    <!-- TODO: a jarjar format would be better --> 
    <id>jar-with-dependencies</id> 
    <formats> 
     <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <dependencySets> 
     <dependencySet> 
      <outputDirectory>/</outputDirectory> 
      <unpack>true</unpack> 
      <unpackOptions> 
       <excludes> 
        <exclude>META-INF/spring.handlers</exclude> 
        <exclude>META-INF/spring.schemas</exclude> 
       </excludes> 
      </unpackOptions> 
      <scope>runtime</scope> 
     </dependencySet> 
    </dependencySets> 
    <files> 
     <file> 
      <source>${project.basedir}/src/main/resources/META-INF/spring.handlers</source> 
      <outputDirectory>META-INF</outputDirectory> 
     </file> 
     <file> 
      <source>${project.basedir}/src/main/resources/META-INF/spring.schemas</source> 
      <outputDirectory>META-INF</outputDirectory> 
     </file> 
    </files> 
</assembly> 
+0

वास्तव में यह समाधान बेहतर और अधिक सामान्य है। जब मुझे पहले के बहिष्कार किसी कारण से मेरे लिए काम करना बंद कर दिया था तो मुझे खुद पर वापस गिरना पड़ा। – Mojo

+0

मुझे उसी प्रोजेक्ट में कक्षाओं को शामिल करने के लिए true जोड़ना था। – jontro

1

मैं इसे बाहर काम किया है, और यहाँ हैं विवरण:

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

असेंबली प्लग-इन दस्तावेज़ नमूना jar-with-dependencies descriptor here देता है।

मैंने अपनी प्रोजेक्ट निर्देशिका में exec-jar.xml नामक फ़ाइल में उस वर्णनकर्ता की प्रतिलिपि बनाई और चिपकाया। फिर पोम में, मैंने डिस्क्रिप्टर को संदर्भित करने के लिए असेंबली प्लग-इन बदल दिया। यहाँ अंश है:

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <version>2.2-beta-3</version> 
     <configuration> 
      <descriptors> 
       <descriptor>exec-jar.xml</descriptor> 
      </descriptors> 
      <archive> 
       <manifest> 
        <mainClass>com.package.MyMainClass</mainClass> 
       </manifest> 
      </archive> 
     </configuration> 
     <executions> 
      <execution> 
       <id>make-assembly</id> 
       <phase>package</phase> 
       <goals> 
        <goal>single</goal> 
       </goals> 
      </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build> 

वर्णनकर्ता का वह थोड़ा जीवन चक्र के पैकेज चरण के लिए विधानसभा बांधता है, और संदर्भ कार्यकारी-jar.xml वर्णनकर्ता। उस पैकेज को करने से पुष्टि हुई कि जार को पूर्वनिर्धारित वर्णनकर्ता के साथ बनाया गया था।

तो फिर यह वसंत फ़ाइलों के साथ संघर्ष करने वाली सीएक्सएफ फाइलों को बाहर करने के लिए exec-jar.xml को संशोधित करने का मामला बन जाता है। यहां मेरा असेंबली डिस्क्रिप्टर है जो पूरा करता है:

<assembly> 
    <id>jar-with-dependencies</id> 
    <formats> 
    <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <dependencySets> 
    <dependencySet> 
     <unpack>true</unpack> 
     <unpackOptions> 
     <excludes> 
      <exclude>cxf*/META-INF/spring.handlers</exclude> 
      <exclude>cxf*/META-INF/spring.schemas</exclude> 
     </excludes> 
     </unpackOptions> 
     <scope>runtime</scope> 
    </dependencySet> 
    </dependencySets> 
    <fileSets> 
    <fileSet> 
     <directory>${project.build.outputDirectory}</directory> 
    </fileSet> 
    </fileSets> 
</assembly> 

अब यहां रगड़ है। यदि आप वर्तमान में जारी किए गए असेंबली प्लग-इन, संस्करण 2.1 के साथ ऐसा करते हैं, तो यह टैग पर "अप्रत्याशित" के रूप में विफल हो जाएगा। टैग प्लग-इन के रिलीज़ संस्करण 2.2 में समर्थित है। उपरोक्त मेरे पोम फ़ाइल अंश में नोट, मैं मैवेन-असेंबली-प्लगइन संस्करण 2.2-बीटा -3 निर्दिष्ट करता हूं जो लेखन के समय नवीनतम था।

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

5

मैं इसके बजाय मेवेन-शेड-प्लगइन का उपयोग करने का सुझाव दूंगा। यदि आप cxf-bundle (http://svn.apache.org/repos/asf/cxf/trunk/distribution/bundle/all/pom.xml) के लिए पोम देखते हैं तो आप देख सकते हैं कि कैसे आप spring.schemas और अन्य आवश्यक फ़ाइलों को मर्ज करने के लिए छाया ट्रांसफॉर्मर का उपयोग कर सकते हैं।

+0

यह भी http://www.hagelnx.com/prog/814 पर अच्छी तरह से वर्णित है। –

1

आप spring.schemas और spring.handlers फ़ाइलों को वसंत डिस्ट्रो से प्राप्त करके समस्या के आसपास भी काम कर सकते हैं और उन्हें अपनी परियोजनाओं में स्रोत/मुख्य/संसाधन/मेटा-आईएनएफ निर्देशिका में डाल सकते हैं। चूंकि वे आखिरी बार पैक किए जाते हैं, इसलिए आपको वह संस्करण मिल जाएगा जो आप चाहते हैं। मुझे लगता है कि here

5

मैंने छाया प्लगइन दृष्टिकोण की कोशिश की और यह बहुत अच्छी तरह से काम किया। यहां आपको केवल अपनी पीओएम डालने की ज़रूरत है (कोई असेंबली प्लगइन आवश्यक नहीं है)।

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>1.4</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
        <configuration> 
         <transformers> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
           <mainClass>org.example.Runner</mainClass> 
          </transformer> 
          <transformer 
           implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
           <resource>META-INF/spring.handlers</resource> 
          </transformer> 
         </transformers> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
+0

यह मेरे लिए काम किया –

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