views:

379

answers:

2

I have a situation where I have a web application that is built using maven (i.e., maven-war-plugin). For each code modification, we have had to manually launch maven and restart the application server. Now, to reduce build cycle overhead, I want to use WTP to publish the webapp.

Now, we have resource processing with Maven, and there are some additional Maven tasks defined in our POM when building the webapp. Therefore m2eclipse seems like a natural solution.

I have gotten far enough that the Maven builder is running these tasks and filtering resources correctly. However, when I choose "Run on Server", the WAR file does not look like it would if I built it in Maven.

I am guessing that this is because WTP actually builds the WAR, and not the m2eclipse builder. So even though we have configured the maven-war-plugin in our POM, those settings are not used.

Below is a snippet with our maven-war-plugin configuration. What is configured under "webResources" is not picked up, it appears:

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-2</version>
<configuration>
 <outputDirectory>${project.build.directory}</outputDirectory>
 <workDirectory>${project.build.directory}/work</workDirectory>
 <webappDirectory>${project.build.webappDirectory}</webappDirectory>
 <cacheFile>${project.build.webappDirectory}/webapp-cache.xml</cacheFile>
 <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
 <nonFilteredFileExtensions>
  <nonFilteredFileExtension>pdf</nonFilteredFileExtension>
  <nonFilteredFileExtension>png</nonFilteredFileExtension>
  <nonFilteredFileExtension>gif</nonFilteredFileExtension>
  <nonFilteredFileExtension>jsp</nonFilteredFileExtension>
 </nonFilteredFileExtensions>
 <webResources>
 <!-- Add generated WSDL:s and XSD:s for the web service api. -->
   <resource>
   <directory>${project.build.directory}/jaxws/wsgen/wsdl</directory>
   <targetPath>WEB-INF/wsdl</targetPath>
   <filtering>false</filtering> 
   <includes>
     <include>**/*</include>
   </includes>
 </resource>               
 </webResources>
 </configuration>

Do I need to reconfigure these resources to be handled elsewhere, or is there a better solution?

+1  A: 

I'm not sure (filtered) web resources are supported yet, see MNGECLIPSE-1149. The issue has a patch (and a workaround) that could work for you. Also have a look at the hack from this thread.

Pascal Thivent
Thanks! I ended up using the hack from the thread in this case.
waxwing
A: 

To fill in an answer to my own question if someone else comes across the same problem, I ended up adding the following to my webapp project:

<resource>
  <directory>${project.build.directory}/jaxws/wsgen/wsdl</directory>
  <filtering>true</filtering>
  <targetPath>${project.basedir}/src/main/webapp/WEB-INF/wsdl</targetPath>
  <includes>
    <include>**/*</include>
  </includes>
</resource>

(inside the resources element under build).

It works fine since my WSDL files are generated in the generate-resources phase and places them in target/jaxws/wsgen/wsdl. Then those are moved into src/main/webapp/WEB-INF/wsdl, where the WTP builder picks them up when building the WAR file.

Note: I should mention that I get some problems with the eclipse plugin for Maven now (i.e., mvn eclipse:eclipse), because apparently you are not allowed to have absolute paths in targetPath. Not found a satisfactory workaround yet...

waxwing