maven: How to add resources which are generated after compilation phase

前端 未结 1 574
别那么骄傲
别那么骄傲 2021-02-01 02:12

I have a maven project which uses wsgen to generate XSD files from the compiled java classes.

The problem is that I want to add the generated files to the jar as resou

相关标签:
1条回答
  • 2021-02-01 03:02

    I would suggest to define the output directory for the XSD files into target/classes (may be with a supplemental sub folder which will be packaged later during the package phase into the jar. This can be achieved by using the maven-resources-plugin.

    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.2</version>
            <executions>
              <execution>
                <id>copy-resources</id>
                <phase>process-classes</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                  <resources>          
                    <resource>
                      <directory>${basedir}/target/xsd-out</directory>
                      <filtering>false</filtering>
                    </resource>
                  </resources>              
                </configuration>            
              </execution>
            </executions>
          </plugin>
        </plugins>
        ...
      </build>
      ...
    </project>
    

    You need to take care that the resources plugin is positioned after the plugin which is used to call the wsgen part. You can also use the prepare-package phase instead to make sure the resources will be correctly packaged.

    0 讨论(0)
提交回复
热议问题