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

点点圈 提交于 2019-12-10 13:59:22

问题


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


回答1:


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).




回答2:


Take a look at this link. It describes how to customize navigation and add resources to the Maven generated site.



来源:https://stackoverflow.com/questions/2503293/how-to-add-a-file-from-my-source-tree-to-maven-site

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!