2012-06-22 15 views
28

मेरे पास एक मेवेन आधारित स्प्रिंग-डब्ल्यूएस क्लाइंट प्रोजेक्ट है जिसे मैं एक जार के रूप में पैकेज करना चाहता हूं। ग्रहण में, सब कुछ ठीक से चलता है। जब मैं इसे निष्पादन योग्य जार के रूप में पैकेज करने का प्रयास करता हूं, तो मुझे क्लास नॉटफाउंड अपवाद मिलते हैं क्योंकि स्प्रिंग जार मेरे एप्लिकेशन जार में शामिल नहीं होते हैं।मेवेन के साथ वसंत-आधारित निष्पादन योग्य जार कैसे बनाएं?

तो मैंने अपने आवेदन जार में मेरी सभी निर्भरताओं को शामिल करने के लिए maven-shade-plugin जोड़ा। जब मैं अपने ऐप जार को देखता हूं, तो मैं सभी निर्भरताओं से सभी वर्ग फ़ाइलों को शामिल करता हूं (सभी पुस्तकालय जार विस्फोटित होते हैं)।

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.4</version> 
      <configuration> 
       <archive> 
        <manifest> 
         <addClasspath>true</addClasspath> 
         <mainClass>com.cws.cs.Client</mainClass> 
        </manifest> 
       </archive> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>1.7</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
       </execution> 
      </executions> 

     </plugin> 
    </plugins> 
</build> 

मेरे समस्या यह है कि पैकेजिंग प्रक्रिया में, अपने एक से अधिक वसंत निर्भरता अलग META-INF/spring.schemas फ़ाइलों कि एक दूसरे को ओवरराइड है। नतीजतन, मेरे अंतिम जार में एक अपूर्ण वसंत.schemas फ़ाइल है।

तो जब मैं अपना निष्पादन योग्य जार चलाने की कोशिश करता हूं, तो मुझे स्प्रिंग त्रुटि संदेश मिलते हैं कि वसंत.schemas फ़ाइल अधूरा होने के बाद से फ़ाइलें नहीं मिल सकती हैं (स्प्रिंग-डब्ल्यूएस के जार ने स्प्रिंग-कोर की spring.schemas फ़ाइल को ओवरराइड कर दिया है)।

मेरे निष्पादन योग्य जार के META-INF/spring.schemas:

http\://www.springframework.org/schema/web-services/web-services-1.5.xsd=/org/springframework/ws/config/web-services-1.5.xsd 
http\://www.springframework.org/schema/web-services/web-services-2.0.xsd=/org/springframework/ws/config/web-services-2.0.xsd 
http\://www.springframework.org/schema/web-services/web-services.xsd=/org/springframework/ws/config/web-services-2.0.xsd 
वसंत-beans.jar META-INF/spring.schemas के बजाय

:

http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd 
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd 
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd 
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd 
http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd 
http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd 
http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd 
http\://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd 
http\://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd 
http\://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd 
http\://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd 
http\://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd 
http\://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd 
http\://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd 
http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd 

मैं स्टंप्डया हूँ। मुझे यकीन नहीं है कि मैं एक निष्पादन योग्य जार के रूप में सब कुछ कैसे पैकेज कर सकता हूं। मुझे नहीं पता कि यह एक छाया-प्लगइन कॉन्फ़िगरेशन समस्या है, या यदि मैं कुछ असंभव करने की कोशिश कर रहा हूं। यह सही नहीं लगेगा कि मुझे मैन्युअल रूप से अपनी खुद की spring.schemas फ़ाइल (दूसरों का एक संयोजन) बनाना होगा।

मैंने बंदूक को थोड़ा सा कूद दिया होगा। छाया प्लगइन पर अधिक जानकारी खोदने में, मैंने AppendingTransformer देखा जो मैंने पहले छोड़ा था। हालांकि, मेरी चिंता यह जानना है कि अन्य फाइलों में कौन सी फाइलें हैं? मैंने इस विशेष वसंत मुद्दे को खोज लिया/पकड़ा है। मुझे किसी भी अन्य पुस्तकालयों के बारे में कोई जानकारी नहीं है जो कुछ ऐसा कर सकता है ...

किसी भी सुझाव की सराहना की जाएगी।

+0

वैकल्पिक दृष्टिकोण है जो अच्छा काम करता है अलग lib फ़ोल्डर में वसंत जार रखें, और प्रकट में वर्ग पथ में इस 'lib' फ़ोल्डर जोड़ने के लिए है - आंद्रे Aronsen देखते हैं उत्तर http://stackoverflow.com/a/4323501/241986 –

उत्तर

6

मैवेन-शेड-प्लगइन उपयोग के बजाय onejar-maven-pluginOne-JAR आपको एक जावा एप्लिकेशन को अपनी निर्भरता जार के साथ एक निष्पादन योग्य जार फ़ाइल में पैकेज करने देता है।

+3

एक-जार प्लगइन के साथ मेरी समस्या यह है कि यह एक-jar.jar एक्सटेंशन के साथ लक्षित फ़ोल्डर में दूसरा जार बनाता है। नतीजतन, जब मैं आर्टिफैक्ट को तैनात करने की कोशिश करता हूं, तो यह मूल जार को तैनात करता है, न कि एक-जार। क्या आपको पता है कि इस मुद्दे से बचने के लिए पोम को कॉन्फ़िगर करने का कोई उचित तरीका है या नहीं? –

+0

'वन-जार' एक-जेर प्लगइन द्वारा जोड़ा गया एक डिफ़ॉल्ट क्लासिफायरफायर है। Http://onejar-maven-plugin.googlecode.com/svn/mavensite/usage.html उस वर्गीकरण का उपयोग करने के लिए तैनाती को कॉन्फ़िगर करें http://stackoverflow.com/questions/9743574/maven-how-to-install-a- jar-with-a-classifier-and-not-install-the-default-one – amra

57

आप निम्न कॉन्फ़िगरेशन जोड़ सकते हैं ताकि सभी जारों से .schema फ़ाइलों की सामग्री एक साथ जुड़ जाए।

<configuration> 
    <transformers> 
    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
     <resource>META-INF/spring.handlers</resource> 
    </transformer> 
    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
     <resource>META-INF/spring.schemas</resource> 
    </transformer> 
    </transformers> 
</configuration> 
+1

धन्यवाद - मैंने वही चीज़ देखी और उस जानकारी को शामिल करने के लिए अभी मेरे प्रश्न को संपादित किया था। मेरा प्रश्न/समस्या यह जानना है कि क्या कोई अन्य पुस्तकालय हैं जो समान समस्याओं का सामना कर रहे हैं? मुझे उन सभी libs के लिए सभी मेटा-आईएनएफ फ़ोल्डरों की सामग्री जानने की उम्मीद नहीं की जा सकती है जो मैं उपयोग करता हूं ... –

+0

शायद विश्लेषण द्वारा पता लगाने का कोई तरीका नहीं है। एकमात्र व्यावहारिक विकल्प कुछ परीक्षण करने के लिए है, सुनिश्चित करें कि यह काम करता है और टूटा हुआ कुछ भी ठीक करता है। – gkamal

+0

@gkamal इसका मतलब क्या है 'एक साथ जोड़ा गया' क्या एक ही फ़ाइल नाम वाली फाइलें एक 'जार' में पैक होने पर एक-दूसरे को ओवरराइड नहीं करती हैं? जार में एक ही नाम के साथ अलग-अलग फाइलें कैसे टकरा नहीं सकतीं? – Jas

1

क्या आपने maven-assembly-plugin को आजमाया है?

यह आप के लिए निर्भरता के साथ एक एकल जार बना सकते हैं और morevover यह इस जार निष्पादन योग्य होना कर सकते हैं होगा:

उपयोग mainClass वर्ग आप पर अमल करना चाहते हैं निर्दिष्ट करने के लिए।

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.3</version> 
    <configuration> 
     <descriptorRefs> 
     <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
     <archive> 
     <manifest> 
      <mainClass>org.sample.App</mainClass> 
     </manifest> 
     </archive> 
    </configuration> 
    <executions> 
     <execution> 
     <id>make-assembly</id> <!-- this is used for inheritance merges --> 
     <phase>package</phase> <!-- bind to the packaging phase --> 
     <goals> 
      <goal>single</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 
+3

छाया और असेंबली प्लगइन्स एक ही अवधारणा हैं। वे दोनों निर्भरताओं को विस्फोट करेंगे और उन्हें उसी क्षेत्र में शामिल करने का प्रयास करेंगे। दोनों समस्याएं तब चलते हैं जब एकाधिक निर्भरताओं में एक ही पथ में फ़ाइलें होती हैं (उदा: मेटा-आईएनएफ/spring.schemas) –

4

कल मुझे इस मुद्दे का भी सामना करना पड़ा।

समाधान इस से मैनुअल संयोजन और विधानसभा प्लगइन का विन्यास द्वारा आवश्यक फ़ाइलें तैयार करने के लिए किया गया था:

<files> 
    <file> 
     <source>src/META-INF/spring.schemas</source> 
     <outputDirectory>META-INF</outputDirectory> 
    </file> 
    <file> 
     <source>src/META-INF/spring.handlers</source> 
     <outputDirectory>META-INF</outputDirectory> 
    </file> 
    </files> 
    <dependencySets> 
    <dependencySet> 
     <outputDirectory>/</outputDirectory> 
     <useProjectArtifact>true</useProjectArtifact> 
     <unpack>true</unpack> 
     <scope>runtime</scope> 
     <unpackOptions> 
     <excludes> 
      <exclude>META-INF/spring.handlers</exclude> 
      <exclude>META-INF/spring.schemas</exclude> 
     </excludes> 
     </unpackOptions> 
    </dependencySet> 
    </dependencySets> 

नोट: एक जार दृष्टिकोण का उपयोग कर काफी अच्छा नहीं है - आप हाथ मिश्रित फ़ाइलों पर निश्चित नहीं हो सकते , सभी निर्भरता के रूप में है के निर्यात रखने की कोशिश ...

1
assembly plugin have issues, use below plugin 

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>shade</goal> 
      </goals> 
      <configuration> 
       <transformers> 
        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
         <mainClass>at.seresunit.lecturemanager_connector.App</mainClass> 
        </transformer> 
        <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
         <resource>META-INF/spring.handlers</resource> 
        </transformer> 
        <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
         <resource>META-INF/spring.schemas</resource> 
        </transformer> 
       </transformers> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

you may get security exception resolve it using below configuration 

<configuration> 
    <filters> 
     <filter> 
      <artifact>*:*</artifact> 
      <excludes> 
       <exclude>META-INF/*.SF</exclude> 
       <exclude>META-INF/*.DSA</exclude> 
       <exclude>META-INF/*.RSA</exclude> 
      </excludes> 
     </filter> 
    </filters> 
</configuration>