2012-03-31 81 views
2

我正在使用Eclipse Indigo和M2E通過WTP部署本地Web應用程序。我也使用yui-compressor插件,它似乎在目標下的爆炸戰爭目錄中工作正常,但不支持eclipse WTP。有沒有推薦的方法來設置這個,所以我可以在本地開發並使用縮小的文件?yui壓縮機maven插件可以使用WTP嗎?

這裏是我的衣配置:

<plugin> 
      <groupId>net.alchim31.maven</groupId> 
      <artifactId>yuicompressor-maven-plugin</artifactId> 
      <version>1.3.0</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>compress</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <nosuffix>true</nosuffix> 
       <force>true</force> 
       <jswarn>false</jswarn> 
       <linebreakpos>-1</linebreakpos> 
       <excludes> 
        <exclude>**/lib/*</exclude> 
       </excludes> 
       <aggregations> 
        <aggregation> 
         <insertNewLine>true</insertNewLine> 
         <output>${project.build.directory}/${project.build.finalName}/static/js/script-${timestamp}.min.js</output> 
         <includes> 
          <include>**/script/*.js</include> 
         </includes> 
         <excludes> 
          <exclude>**/lib/*</exclude> 
         </excludes> 
        </aggregation> 
       </aggregations> 
      </configuration> 
     </plugin> 

<pluginManagement> 
     <plugins> 
      <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.2,)</versionRange> 
            <goals> 
             <goal>compress</goal> 
            </goals> 
           </pluginExecutionFilter> 
           <action> 
            <execute /> 
           </action> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 

回答

0

的問題,我認爲,是你講的不是要maven-war-plugin在哪裏可以找到生成的資源。

您應該嘗試將webResources部分添加到maven-war-plugin配置中,例如,

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <configuration> 
     <webResources> 
     <resource> 
      <filtering>true</filtering> 
      <directory>${basedir}/src/main/webapp</directory> 
      <excludes> 
      <exclude>**/pattern-for-non-minified-scripts</exclude> 
      </excludes> 
     </resource> 
     <resource> 
      <filtering>true</filtering> 
      <directory>${project.build.directory}/${project.build.finalName}</directory> 
      <includes> 
      <include>static/js/script-${timestamp}.min.js</include> 
      </includes> 
     </resource> 
     </webResources> 
    </configuration> 
    </plugin> 

要查看WTP回升縮小的文件,檢查.settings/org.eclipse.wst.common.component文件中有如下一行:

<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> 
+0

謝謝,這樣做後,我可以看到資源被放在網絡資源文件夾中並縮小。不過,似乎我無法逐步完成此操作。儘管yui插件可以在任何資源保存後運行,但除非再次執行構建,否則更改不會推送到web資源文件夾。有沒有辦法解決這個問題,所以我可以使用它與WTP? – user842800 2012-04-01 17:51:34

0

你嘗試<runOnIncremental>true</runOnIncremental>

<pluginManagement> 
    <plugins> 
     <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.3.0,)</versionRange> 
           <goals> 
            <goal>compress</goal> 
           </goals> 
          </pluginExecutionFilter> 
          <action> 
           <execute> 
            <runOnIncremental>true</runOnIncremental> 
           </execute> 
          </action> 
         </pluginExecution> 
        </pluginExecutions> 
       </lifecycleMappingMetadata> 
      </configuration> 
     </plugin> 
    </plugins> 
</pluginManagement> 

要讓M2E輸出的文件到/src/目錄,而不是/target/目錄,我使用以下命令:

<plugins> 
    <plugin> 
     <groupId>net.alchim31.maven</groupId> 
     <artifactId>yuicompressor-maven-plugin</artifactId> 
     <version>1.3.0</version> 
     <executions> 
      <execution> 
       <goals> 
        <goal>compress</goal> 
       </goals> 
      </execution> 
     </executions> 
     <configuration> 
      <sourceDirectory>${project.basedir}/src/main/webapp/resources/js</sourceDirectory> 
      <outputDirectory>${project.basedir}/src/main/webapp/resources/js-min</outputDirectory> 
     </configuration> 
    </plugin> 
</plugins> 

在我的HTML我再引用JavaScript文件(S)在[...]/resources/js-min/