Maven - 将客户端项目的资源复制到 Web 应用程序

5
我有一个项目,其中包括 GWT 客户端和 Tomcat 服务器端。所有内容都使用 Maven 进行设置。然而,我想把客户端的 HTML 和 CSS 文件(位于资源文件夹中)复制到服务器项目的 webapp 目录中。我一直在研究 maven-dependency-plugin,但无法使其正常工作。我似乎找不到指定源路径和目标路径的方法。如果有人能指点我正确的方向,我将不胜感激。
谢谢。
4个回答

3
  <!-- 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>

但是资源驻留在另一个已添加为依赖项的Maven项目中。 - GlGuru
我发现这个解决方案对于驻留在外部Maven依赖项中的资源运作良好。虽然我不确定为什么需要这样一个晦涩的方式来包含资源。当标准GWT编译应该包括资源时。 - Nigel_V_Thomas

0
你应该在与 <module_name>.gwt.xml 模块配置文件相同的级别上创建一个public文件夹。也就是说:
+src/main/resources
|-<module_name>.gwt.xml
|-+public
  |-<static resources>

这样,在gwt编译后,所有资源都将进入 src/main/webapp/<module_name>/。这个文件夹是maven(通过插件)或您(手动)用来创建最终web应用程序的文件夹。

希望这可以帮到您。
祝好


0
在你的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>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接