我有一個由GWT客戶端和Tomcat服務器端組成的項目。一切都使用maven進行設置。但是,我希望將客戶端的HTML和CSS文件(位於資源文件夾中)複製到服務器項目webapp目錄中。我一直在看maven-dependency-plugin,但無法讓它工作。我似乎無法找到指定源和目標路徑的方法。如果有人能指出我正確的方向,我將不勝感激。Maven - 將資源從客戶端項目複製到webapp
謝謝。
我有一個由GWT客戶端和Tomcat服務器端組成的項目。一切都使用maven進行設置。但是,我希望將客戶端的HTML和CSS文件(位於資源文件夾中)複製到服務器項目webapp目錄中。我一直在看maven-dependency-plugin,但無法讓它工作。我似乎無法找到指定源和目標路徑的方法。如果有人能指出我正確的方向,我將不勝感激。Maven - 將資源從客戶端項目複製到webapp
謝謝。
<!-- Use the following to extract all files from the dependent jar or war (see type) : -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.group.id</groupId>
<artifactId>artifact-id</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>target/exploded-artifact-id-jar</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<!-- then copy the neccessary files to the webapp directory -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copy-webapp-resources</id>
<phase>generate-resources</phase>
<configuration>
<tasks>
<copy todir="target/webapp" filtering="false">
<fileset dir="target/exploded-artifact-id-jar/path-to-files"/>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
你應該在同一水平的<module_name>.gwt.xml
模塊配置文件創建一個public
文件夾。那就是:
+src/main/resources
|-<module_name>.gwt.xml
|-+public
|-<static resources>
這樣,在gwt編譯之後,所有的資源都會去src/main/webapp/<module_name>/
。該文件夾是maven(通過插件)或你(手動)將用於創建最終的webapp的文件夾。
希望這會有所幫助。
問候
在阿帕奇的Maven看看Maven的戰爭插件頁面:
http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
在你pom.xml
,你可以指定你需要使用的資源。例如:
<build>
<!-- Resources to be bundeled with the final WAR -->
<resources>
<resource>
<directory>config</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
但是這些資源駐留在另一個作爲依賴關係添加的maven項目中。 – GlGuru 2010-11-14 19:03:32
我發現此解決方案適用於駐留在外部Maven依賴項中的資源。雖然我不確定爲什麼需要這樣一種包含資源的遲鈍方式。標準的gwt編譯應該包含資源。 – 2013-09-13 14:28:04