9

का उपयोग कर आर्टिफैक्ट के लिए मेवेन निर्भरता बदलें मैवेन जार प्लगइन के साथ मैं दो जार: बार-1.0.0.jar और बार-1.0.0-client.jar बनाता हूं।वर्गीकृत

असल में मेरी पोम

मैं निम्नलिखित निर्भरता:

<dependency> 
    <groupId>de.app.test</groupId> 
    <artifactId>foo</artifactId> 
    <version>1.0.0</version> 
</dependency> 

यह विरूपण साक्ष्य दो संस्करण बार-1.0.0.jar और बार-1.0.0-client.jar

में भी मौजूद हैं मैं foo-1.0.0-client.jar को foo-1.0.0-client.jar और bar-1.0.0.jar पर निर्भर करता हूं foo-1.0.0.jar पर निर्भर करता है।

================

-> सबसे पहले (गलत) समाधान: जब bar.jar

का उपयोग कर के रूप में प्रदान की है और सही foo पैकेज का उपयोग दायरे को परिभाषित

-> दूसरा (लंबा) समाधान: अन्य जार में 'सर्वर' क्लासिफायर जोड़ें। Foo artifact बनाने के लिए अलग-अलग प्रोफ़ाइल का उपयोग करें और वर्गीकरण को किसी संपत्ति में रखें।

<dependency> 
    <groupId>de.app.test</groupId> 
    <artifactId>foo</artifactId> 
    <version>1.0.0</version> 
    <classifier>${profile.classifier}<classifier> 
</dependency> 

================
प्रोफ़ाइल समाधान के संबंध में।

इंटरफेस मॉड्यूल पोम

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <parent> 
     <groupId>com.app</groupId> 
     <artifactId>myapp-parent</artifactId> 
     <version>1.1.0</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.app</groupId> 
    <artifactId>myapp-interfaces</artifactId> 
    <version>1.1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 
    <name>myapp Interfaces</name> 
    <profiles> 
     <profile> 
      <id>server</id> 
      <activation> 
       <activeByDefault>true</activeByDefault> 
      </activation> 
      <build> 
       <plugins> 
        <plugin> 
         <artifactId>maven-jar-plugin</artifactId> 
         <executions> 
          <execution> 
           <id>jar-server</id> 
           <phase>package</phase> 
           <goals> 
            <goal>jar</goal> 
           </goals> 
           <configuration> 
            <classifier>server</classifier> 
           </configuration> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 
     <profile> 
      <id>client</id> 
      <activation> 
       <activeByDefault>true</activeByDefault> 
      </activation> 
      <build> 
       <plugins> 
        <plugin> 
         <artifactId>maven-jar-plugin</artifactId> 
         <executions> 
          <execution> 
           <id>jar-client</id> 
           <phase>package</phase> 
           <goals> 
            <goal>jar</goal> 
           </goals> 
           <configuration> 
            <classifier>client</classifier> 
            <excludes> 
             <exclude>**/server/**</exclude> 
            </excludes> 
           </configuration> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 
    </profiles> 
</project> 

कार्यान्वयन मॉड्यूल पोम

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <parent> 
     <groupId>com.app</groupId> 
     <artifactId>myapp-parent</artifactId> 
     <version>1.1.0-SNAPSHOT</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.app</groupId> 
    <artifactId>myapp-model</artifactId> 
    <version>1.1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 
    <name>myapp Model</name> 
    <properties> 
     <myapp-interfaces.classifier></myapp-interfaces.classifier> 
     <myapp-interfaces.version>1.1.0-SNAPSHOT</myapp-interfaces.version> 

    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>com.app</groupId> 
      <artifactId>myapp-interfaces</artifactId> 
      <version>${myapp-interfaces.version}</version> 
      <classifier>${myapp-interfaces.classifier}</classifier> 
     </dependency> 
     [...] 
    </dependencies> 
    <profiles> 
     <profile> 
      <id>server</id> 
      <build> 
       <plugins> 
        <plugin> 
         <artifactId>maven-jar-plugin</artifactId> 
         <executions> 
          <execution> 
           <id>jar-server</id> 
           <phase>package</phase> 
           <goals> 
            <goal>jar</goal> 
           </goals> 
           <configuration> 
            <classifier>server</classifier> 
           </configuration> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 
      <dependencies> 
       <dependency> 
        <groupId>com.app</groupId> 
        <artifactId>myapp-interfaces</artifactId> 
        <version>${myapp-interfaces.version}</version> 
        <classifier>${myapp-interfaces.classifier}</classifier> 
       </dependency> 
      </dependencies> 
      <properties> 
       <myapp-interfaces.classifier>server</myapp-interfaces.classifier> 
      </properties> 
     </profile> 
     <profile> 
      <id>client</id> 
      <build> 
       <plugins> 
        <plugin> 
         <artifactId>maven-jar-plugin</artifactId> 
         <executions> 
          <execution> 
           <id>jar-client</id> 
           <phase>package</phase> 
           <goals> 
            <goal>jar</goal> 
           </goals> 
           <configuration> 
            <classifier>client</classifier> 
            <excludes> 
             <exclude>**/server/**</exclude> 
             <exclude>**/META-INF/services/**</exclude> 
            </excludes> 
           </configuration> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 
      <properties> 
       <myapp-interfaces.classifier>client</myapp-interfaces.classifier> 
      </properties> 
      <dependencies> 
       <dependency> 
        <groupId>com.app</groupId> 
        <artifactId>myapp-interfaces</artifactId> 
        <version>${myapp-interfaces.version}</version> 
        <classifier>${myapp-interfaces.classifier}</classifier> 
       </dependency> 
      </dependencies> 
     </profile> 
    </profiles> 
</project> 

इस समाधान के साथ समस्या यह है कि मेरे मुवक्किल इंटरफेस के दौरान एक संकलन त्रुटि फेंक कुछ याद आ रही इंटरफेस और Maven है की वजह से है संकलन चरण।

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

मुझे आश्चर्य है कि क्या एक जार बनाना संभव है और एक विशिष्ट पोम अंदर रखना संभव है?

+1

लंबे समाधान सही है। तो सवाल क्या है? –

+0

वास्तव में यह काम नहीं किया। क्योंकि मेरे foo-server और foo-client में मेरे पास कुछ इंटरफेस नहीं हटाए गए थे। जब मैं प्रोजेक्ट का निर्माण करता हूं तो मुझे कुछ संकलन त्रुटि का सामना करना पड़ता है। मैं इस मुद्दे को समझाने के लिए अपने प्रश्न को संपादित करूंगा। – Vlagorce

+0

एक ही मुद्दे के बारे में एक पुराना सवाल [1]: http: //www.mail-archive.com/[email protected]/msg102761.html – Vlagorce

उत्तर

6

इंटरफेस के लिए।

मैं कुछ भी नहीं बदलता और दोनों interfaces.jar (क्लाइंट + सर्वर) का निर्माण करता हूं।

मॉडल के लिए मैं दोनों वैकल्पिक रूप

<dependency> 
     <groupId>com.app</groupId> 
     <artifactId>myapp-interfaces</artifactId> 
     <version>${myapp-interfaces.version}</version> 
     <classifier>client</classifier> 
     <optional>true</optional> 
    </dependency> 
    <dependency> 
     <groupId>com.app</groupId> 
     <artifactId>myapp-interfaces</artifactId> 
     <version>${myapp-interfaces.version}</version> 
     <classifier>server</classifier> 
     <optional>true</optional> 
    </dependency> 

कि मैं किसी भी त्रुटि के बिना दोनों मॉडल के संस्करण का निर्माण कर सकते के साथ जार आयात करते हैं।

मेरे मुवक्किल आवेदन और सर्वर अनुप्रयोग

प्रत्येक अनुप्रयोग के लिए मैं सही interfaces.jar निर्भरता बना सकते हैं और models.jar

+1

मुझे लगता है कि आपने क्लासिफायरों को मिश्रित किया है - एक 'क्लाइंट' होना चाहिए, दूसरा - 'सर्वर' होना चाहिए। – carlspring

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