简体   繁体   English

Maven - 将资源从客户端项目复制到webapp

[英]Maven - Copying resources from client project to webapp

I have a project which consists of GWT client end and a Tomcat server end. 我有一个由GWT客户端和Tomcat服务器端组成的项目。 Everything is setup using maven. 一切都是使用maven设置的。 However, I want the client's HTML and CSS files (which reside in the resources folder) to be copied to the server projects webapp directory. 但是,我希望将客户端的HTML和CSS文件(位于resources文件夹中)复制到服务器项目webapp目录中。 I have been looking at the maven-dependency-plugin but cannot get it to work. 我一直在看maven-dependency-plugin,但无法让它工作。 I cannot seem to find a way to specify the source and destination path. 我似乎找不到指定源和目标路径的方法。 I'd appreciate if someone can point me in the right direction. 如果有人能指出我正确的方向,我会很感激。

Thanks. 谢谢。

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

You should create a public folder at the same level that the <module_name>.gwt.xml module config file. 您应该创建一个public处于同一级别的文件夹<module_name>.gwt.xml模块的配置文件。 That is: 那是:

+src/main/resources
|-<module_name>.gwt.xml
|-+public
  |-<static resources>

In that way, after gwt compilation, all the resources will go to src/main/webapp/<module_name>/ . 这样,在gwt编译之后,所有资源都将转到src/main/webapp/<module_name>/ That folder is the one that maven (through the plugin) or you (manually) will use to create the final webapp. 该文件夹是maven(通过插件)或您(手动)将用于创建最终webapp的文件夹。

Hope this helps. 希望这可以帮助。
Regards 问候

In your pom.xml , you can specify the resources you need to be used. pom.xml ,您可以指定需要使用的资源。 Eg: 例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM