I've got a Maven project that builds a JAR file.
It also creates a site (using maven-site-plugin
) that describes information about the project.
I'd like to include the resultant html pages generated by the maven-site-plugin
in the resources of the created JAR so that they can be accessed at runtime by a help system.
Is this possible? If so, how?
I've tried using the site:jar
goal but this always creates an additional JAR with "-site" appended, as per the documentation.
I've solved this by using maven-resources-plugin
to copy the site
from the ${project.build.directory}/site
directory to ${project.build.directory}/classes
, which is the contents of the final JAR.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.me</groupId>
<artifactId>site-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<site.directory>${project.build.directory}/site</site.directory>
</properties>
<build>
<resources>
<resource>
<directory>${site.directory}</directory>
</resource>
</resources>
<plugins>
<plugin>
<!-- Include the maven site in the final JAR - we do this by running site:site BEFORE install -->
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>${site.directory}</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>