2012-07-15 32 views
17

मैं इस प्लगइन को अब कुछ घंटों के लिए मैवेन-वॉर-प्लगइन के साथ अच्छी तरह से खेलने के लिए संघर्ष कर रहा हूं और मैंने सोचा कि यह मदद मांगने का समय था। मैं प्लगइन इस प्रकार परिभाषित किया है:yuicompressor maven प्लगइन और मेवेन-वॉर-प्लगइन

<plugin> 
    <groupId>net.alchim31.maven</groupId> 
    <artifactId>yuicompressor-maven-plugin</artifactId> 
    <version>1.3.0</version> 
    <executions> 
     <execution> 
      <id>compressyui</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>compress</goal> 
      </goals> 
      <configuration> 
       <nosuffix>true</nosuffix> 
       <warSourceDirectory>${basedir}/WebContent</warSourceDirectory> 
       <jswarn>false</jswarn> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

अगर मैं हटाने nosuffix = सच तो मैं देख सकता हूँ संकुचित/न्यूनतम किया गया -min.js फ़ाइलों युद्ध के रूप में उम्मीद में मिलता है, लेकिन इस ध्वज के साथ पर वे ओवरराइट किया जा रहा है जब यह युद्ध फ़ाइल बनाता है तो मैवेन-वॉर-प्लगइन (मैं मान रहा हूं) द्वारा। मुझे वास्तव में फ़ाइल नामों की आवश्यकता है, हालांकि ... क्या किसी के पास एक ही फ़ाइल नामों का उपयोग करने के लिए मुझे क्या बदलने की आवश्यकता है और अभी भी अंतिम संस्करण में मिनी संस्करणों को प्राप्त करने का विचार है?

उत्तर

26

ठीक है। आखिरकार मैंने इसे समझ लिया। आपको yuicompressor प्लगइन में <webappDirectory> को परिभाषित करने की आवश्यकता है जिसे मैवेन-वॉर-प्लगइन में <resource> के रूप में संदर्भित किया जा सकता है। उदाहरण में नीचे मैं <directory>${project.build.directory}/min</directory>

<plugin> 
    <groupId>net.alchim31.maven</groupId> 
    <artifactId>yuicompressor-maven-plugin</artifactId> 
    <version>1.3.0</version> 
    <executions> 
     <execution> 
      <id>compressyui</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>compress</goal> 
      </goals> 
      <configuration> 
       <nosuffix>true</nosuffix> 
       <warSourceDirectory>${basedir}/WebContent</warSourceDirectory> 
       <webappDirectory>${project.build.directory}/min</webappDirectory> 
       <jswarn>false</jswarn> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
<plugin> 
    <artifactId>maven-war-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>default-war</id> 
      <phase>package</phase> 
      <goals> 
       <goal>war</goal> 
      </goals> 
      <configuration> 
       <warSourceDirectory>${basedir}/WebContent</warSourceDirectory> 
       <encoding>UTF-8</encoding> 
      </configuration> 
     </execution> 
    </executions> 
    <configuration> 
     <warSourceDirectory>${basedir}/WebContent</warSourceDirectory> 
     <encoding>UTF-8</encoding> 
     <webResources> 
      <resource> 
       <directory>${project.build.directory}/min</directory> 
      </resource> 
     </webResources> 
    </configuration> 
</plugin> 
+2

धन्यवाद, धन्यवाद, धन्यवाद! मुझे एक ही समस्या थी और अब तक कोई समझदार समाधान नहीं मिला। वाईयूआई प्लगइन शब्दावली अत्यधिक भ्रमित आईएमओ है:/ – Rolf

+0

यहां वही :) बहुत आभारी! –

+0

मेरे लिए काम नहीं करता है। युद्ध प्लगइन पहले वेब संसाधनों (minified फाइलों) की प्रतिलिपि बनायेगा, युद्ध स्रोत निर्देशिका की सामग्री के साथ ओवरराइट करें। –

2

उपयोग कर रहा हूँ यह मेरी विन्यास है, और यह मेरी Maven वेब परियोजना में ठीक काम करता है:

<!-- js/css compress --> 
<plugin> 
    <groupId>net.alchim31.maven</groupId> 
    <artifactId>yuicompressor-maven-plugin</artifactId> 
    <version>1.3.2</version> 
    <configuration> 
     <excludes> 
      <exclude>**/*-min.js</exclude> 
      <exclude>**/*.min.js</exclude> 
      <exclude>**/*-min.css</exclude> 
      <exclude>**/*.min.css</exclude> 
     </excludes> 
     <jswarn>false</jswarn> 
     <nosuffix>true</nosuffix> 
    </configuration> 
    <executions> 
     <execution> 
      <id>compress_js_css</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>compress</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
<!-- war --> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.3</version> 
    <configuration> 
     <webResources> 
      <resource> 
       <directory>${project.build.directory}/${project.build.finalName}/resources</directory> 
       <targetPath>/resources</targetPath> 
       <filtering>false</filtering> 
      </resource> 
     </webResources> 
     <webXml>src/main/webapp/WEB-INF/web.xml</webXml> 
    </configuration> 
</plugin> 
8

बस युद्ध प्लगइन पर 'warSourceExcludes' कॉन्फ़िगर करें।

<plugin> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.4</version> 
    <configuration> 
     <warSourceExcludes>**/*.css,**/*.js</warSourceExcludes> 
    </configuration> 
</plugin> 
+0

सरल समाधान जो –

+0

काम करता है धन्यवाद। मेरे प्रोजेक्ट पर काम करता है ठीक है। – Pavlo

3

मैं विन्यास जो मेरे लिए काम किया जोड़ना चाहते हैं:

पहले, 'जीवन चक्र द्वारा कवर नहीं प्लगइन निष्पादन' के बारे में शिकायत m2e ठीक करने के लिए मैं this post से लिया माता पिता पोम में निम्नलिखित जोड़ा :

<pluginManagement> 
    <plugins> 
     <!--This plugin's configuration is used to store Eclipse 
      m2e settings only. It has no influence on the Maven build itself. --> 
     <plugin> 
      <groupId>org.eclipse.m2e</groupId> 
      <artifactId>lifecycle-mapping</artifactId> 
      <version>1.0.0</version> 
      <configuration> 
       <lifecycleMappingMetadata> 
        <pluginExecutions> 
         <pluginExecution> 
          <pluginExecutionFilter> 
           <groupId>net.alchim31.maven</groupId>        
           <artifactId>yuicompressor-maven-plugin</artifactId> 
           <versionRange>[1.0.0,)</versionRange> 
           <goals> 
            <goal>compress</goal> 
           </goals> 
          </pluginExecutionFilter> 
          <action> 
           <execute /> 
          </action> 
         </pluginExecution> 
        </pluginExecutions> 
       </lifecycleMappingMetadata> 
      </configuration> 
     </plugin> 
    </plugins> 
</pluginManagement> 

फिर युद्ध पोम में मैं डाल:

<build> 
    <plugins> 
     <plugin> 
     <groupId>net.alchim31.maven</groupId> 
     <artifactId>yuicompressor-maven-plugin</artifactId> 
     <version>1.4.0</version> 
     <executions> 
     <execution> 
      <goals> 
       <goal>compress</goal> 
      </goals> 
      <configuration> 
       <linebreakpos>300</linebreakpos> 
       <excludes> 
       <exclude>**/*-min.js</exclude> 
       <exclude>**/*.min.js</exclude> 
       <exclude>**/*-min.css</exclude> 
       <exclude>**/*.min.css</exclude> 
       </excludes>    
       <nosuffix>true</nosuffix> 
      </configuration> 
     </execution> 
     </executions> 
     </plugin> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.4</version> 
      <configuration> 
       <warSourceExcludes>**/*.css,**/*.js</warSourceExcludes> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

यह मूल फ़ाइलों को छोड़कर परियोजना निर्माण लक्ष्य निर्देशिका में minified css और js फ़ाइलों को उत्पन्न करता है।

मुझे आशा है कि यह किसी को समय बचाएगा।

0

मैं जिस दृष्टिकोण का उपयोग करता हूं वह थोड़ा अलग है।

सबसे पहले, मैंने संकलन/पैकेजिंग से पहले mvn process-resourcesचलाने के लिए अपना आईडीई कॉन्फ़िगर किया है। इस तरह युद्धों को इकट्ठा करने से पहले फाइलें बनाई जाती हैं।

यह अपने मूल स्रोत फ़ाइलें बदले बिना <nosuffix>false</nosuffix> और <outputDirectory>${basedir}/src/main/resources/</outputDirectory> तो फ़ाइलें एक ही निर्देशिका में बनाया जा सकता है स्थापित करने के लिए बहुत महत्वपूर्ण है।

<plugin> 
    <groupId>net.alchim31.maven</groupId> 
    <artifactId>yuicompressor-maven-plugin</artifactId> 
    <version>1.3.2</version> 
    <configuration> 
     <preProcessAggregates>false</preProcessAggregates> 
     <excludes> 
      <exclude>**/*-min.js</exclude> 
      <exclude>**/*.min.js</exclude> 
      <exclude>**/*-min.css</exclude> 
      <exclude>**/*.min.css</exclude> 
     </excludes> 
     <jswarn>false</jswarn> 
     <nosuffix>false</nosuffix> <!-- VERY IMPORTANT WILL REPLACE YOUR FILES IF YOU SET nosuffix TO TRUE OR DONT SET IT AT ALL --> 
     <outputDirectory>${basedir}/src/main/resources/</outputDirectory> <!-- by default the plugin will copy the minimized version to target directory --> 
     <failOnWarning>false</failOnWarning> 
    </configuration> 

    <executions> 
     <execution> 
      <id>compress_js_css</id> 
       <phase>process-resources</phase> 
      <goals> 
       <goal>compress</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
0

के रूप में जैकब क्रूस कहते हैं, आप * .js के साथ सौदा करना चाहिए, लेकिन कोई * .min.js, इसलिए मेरे विन्यास, नीचे है% regex [] के उपयोग पर ध्यान दें:

\t \t \t <plugin> 
 
\t \t \t  <groupId>net.alchim31.maven</groupId> 
 
\t \t \t  <artifactId>yuicompressor-maven-plugin</artifactId> 
 
\t \t \t  <version>1.4.0</version> 
 
\t \t \t  <executions> 
 
\t \t \t   <execution> 
 
\t \t \t    <id>compressyui</id> 
 
\t \t \t    <phase>process-resources</phase> 
 
\t \t \t    <goals> 
 
\t \t \t     <goal>compress</goal> 
 
\t \t \t    </goals> 
 
\t \t \t    <configuration> 
 
\t \t \t     <nosuffix>true</nosuffix> 
 
\t \t \t     <warSourceDirectory>${basedir}/WebContent</warSourceDirectory> 
 
\t \t \t     <webappDirectory>${project.build.directory}/min</webappDirectory> 
 
\t \t \t     <jswarn>false</jswarn> \t \t 
 
\t \t \t \t   <excludes> 
 
\t \t \t \t    <exclude>**/*-min.js</exclude> 
 
\t \t \t \t    <exclude>**/*.min.js</exclude> 
 
\t \t \t \t    <exclude>**/*-min.css</exclude> 
 
\t \t \t \t    <exclude>**/*.min.css</exclude> 
 

 
\t \t \t \t    <exclude>**/jquery.window.js</exclude> 
 
\t \t \t \t    ...... 
 
\t \t \t \t    <exclude>**/compile.js</exclude> 
 
\t \t \t \t   </excludes> 
 
\t \t \t    </configuration> 
 
\t \t \t   </execution> 
 
\t \t \t  </executions> 
 
\t \t \t </plugin> 
 

 
\t \t \t <plugin> 
 
\t \t \t \t <groupId>org.apache.maven.plugins</groupId> 
 
\t \t \t \t <artifactId>maven-war-plugin</artifactId> 
 
\t \t \t \t <version>2.4</version> 
 
\t \t \t \t <configuration> 
 
\t \t \t \t \t <warSourceDirectory>WebContent</warSourceDirectory> \t \t \t \t \t 
 
\t \t \t \t \t <packagingExcludes>servlet-api*.jar,target/test-classes/*</packagingExcludes> 
 
\t \t \t \t \t <warSourceExcludes>test/**,%regex[.*(!min).js],%regex[.*(!min).css]</warSourceExcludes> 
 
\t \t \t \t 
 
\t \t \t \t \t <webResources> 
 
    \t \t \t \t \t    <resource> 
 
\t \t \t \t \t     <directory>${project.build.directory}/min</directory> 
 
\t \t \t \t \t    </resource> 
 
\t \t \t \t \t </webResources> 
 
\t \t \t \t 
 
\t \t \t \t </configuration> 
 
\t \t \t </plugin>