1

I'm using the maven resources plugin to generate a plain file via filtering within a war file. I have the template file with variables in a the folder src/main/webapp/app

<build>
<plugins>
    ...
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
            <execution>
                <phase>process-resources</phase>
            </execution>
        </executions>
    </plugin>
</plugins>

<resources>
    <resource>
        <directory>src/main/webapp/app</directory>
        <filtering>true</filtering>
    </resource>
</resources>
</build>

the problem is that the generated file is in the WEB-INF/classes folder and I need it to be at the app folder at the root of the war. The war structure should be

*.jsf
app/<generated_file>
WEB-INF/

How can I do it?

taygetos
  • 3,005
  • 2
  • 21
  • 29
jmann
  • 375
  • 1
  • 5
  • 17
  • Possibly related to [this question](https://stackoverflow.com/q/10133485/944849) though not a duplicate. One of the answers there might help. – user944849 Jan 16 '19 at 23:25

2 Answers2

1

You have to add a copy-resources goal if you want to copy something to another structure during your build, with that you can point to a custom output path:

<configuration>
  <outputDirectory>${basedir}/target/extra-resources</outputDirectory>
  <resources>          
    <resource>
      <directory>src/non-packaged-resources</directory>
      <filtering>true</filtering>
    </resource>
  </resources>              
</configuration>

This can be found here in the documentation.

taygetos
  • 3,005
  • 2
  • 21
  • 29
nortontgueno
  • 2,553
  • 1
  • 24
  • 36
  • can you give how you would do it? I use your example configuration with ${basedir}/target/${project.artifactId}-${project.version}/app and src/main/webapp/app .. and still getting the generated file in WEB-INF/classes – jmann Jan 16 '19 at 20:44
  • if I if trigger the copy in the prepare-package phase, it seems that maven is overwriting the generated file with template one in the package phase (the war still has the template file). If I trigger the copy in the package phase, the generated file is copied in the target/ and looks ok but after the war is packaged (so the war still has the template file) – jmann Jan 16 '19 at 21:13
1

With the comments I could finally get the solution. It was simply to set the outputDirectory parameter to src/main/webapp/app and put the template in another place outside src/main/webapp. In my case, I put it in a folder src/main/jnlp. So finally this was the solution.. hope it helps others

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <phase>process-resources</phase>                        
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/src/main/webapp/app</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/jnlp</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>
        </execution>
    </executions>
</plugin>
jmann
  • 375
  • 1
  • 5
  • 17