我使用Maven yui壓縮程序插件和Maven一個jar插件來創建一個容器js和css資源的jar文件。看起來,雖然,我的壓縮的CSS文件總是「一個編譯後面」,這意味着我必須編譯應用程序兩次,以接受一個CSS更改。這裏是我的構建POM的部分插件Yui壓縮器文件在Jar包裝之前未刷新
<!-- Coffee -->
<plugin>
<groupId>com.github.iron9light</groupId>
<artifactId>coffeescript-maven-plugin</artifactId>
<version>1.1.2</version>
<configuration>
<srcDir>src/main/resources</srcDir>
<outputDir>src/main/resources</outputDir>
<bare>false</bare>
<modifiedOnly>false</modifiedOnly>
<allowedDelete>true</allowedDelete>
</configuration>
<executions>
<execution>
<id>coffeescript</id>
<phase>generate-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Sass -->
<plugin>
<groupId>org.jasig.maven</groupId>
<artifactId>sass-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>update-stylesheets</goal>
</goals>
</execution>
</executions>
<configuration>
<sassSourceDirectory>src/main/resources</sassSourceDirectory>
<destination>src/main/resources</destination>
</configuration>
</plugin>
<!-- YUI Compressor -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>**/*.min.js</exclude>
<exclude>**/*.min.css</exclude>
</excludes>
<suffix>.min</suffix>
<outputDirectory>src/main/resources</outputDirectory>
</configuration>
</plugin>
<!-- Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- Jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.example.application.web.JettyStarter</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- One Jar -->
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<onejarVersion>0.97</onejarVersion>
<classifier>onejar</classifier>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
當我檢查我的源代碼樹,我看到過壓縮CSS是存在的,但它不是在瓶子裏。我想比較一下,在單瓶包裝之前將文件「沖洗」出來。有沒有人見過這個?
例子:我已將此添加的style.css
.clear-both {
clear: both;
}
而在style.min.css源樹
.clear-both{clear:both;}
但是,當我要求這個文件在服務器:
GET css/style.min.css
該行不存在。
難道這涉及到與資源插件插件執行的順序:
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MyApp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 661 resources
[INFO]
[INFO] --- yuicompressor-maven-plugin:1.1:compress (default) @ MyApp ---
...
我已經更新了答案排序,但它可以得到改善。什麼都出現在您的src/main/resources目錄中?它只有.coffee腳本和saas源文件嗎? – coderplus 2014-09-21 04:21:58
好的問題,是的,關鍵是要把他們放在流程來源階段。我會看看project.build。目錄也是如此,謝謝你的支持。 – 2014-09-21 18:21:38