Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Add a File from my source tree to Maven Site

Tags:

maven-2

I have a Maven 2 RESTful application using Jersey/JAXB. I generate the JAXB beans from a schema file, where the schema file is in my resources directory, e.g., src/main/resources/foo.xsd.

I want to include foo.xsd file in the generated Maven site for my project, so that clients can see the XML schema when writing RESTful calls.

How can I include foo.xsd in the site?

I could have a copy of the file in src/main/site/..., and then update my site.xml to point to it (or have a .apt whose contents point to it), but I don't like that because I'm still tweaking foo.xsd, and don't want to have to remember to copy it each time I update it. And that's just bad practice.

I also tried having a .apt file that has a link to the foo.xsd which gets copied to the target/classes directory. That works until I do a site:deploy, because that only copies the target/site directory.

Thanks,

Charles

like image 886
Charles O. Avatar asked Mar 23 '10 20:03

Charles O.


1 Answers

To add resources to your site, you'll have to include them in a resources directory:

.
`-- src
    `-- site
        `-- resources
            `-- foo.xsd

To keep this file in sync with the generated one, you could simply use the maven antrun plugin to copy the generated file from src/main/resources to the above location, for example during the pre-site phase:

  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <phase>pre-site</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <tasks>
            <copy file="src/main/resources/foo.xsd" todir="src/site/resources"/>
          </tasks>
        </configuration>
      </execution>
    </executions>
  </plugin>

Finally, add a link to this foo.xsd in your site descriptor (the site.xml file).

like image 99
Pascal Thivent Avatar answered Nov 03 '22 10:11

Pascal Thivent