将Maven生成的站点添加到生成的包中

时间:2010-02-24 17:01:13

标签: maven-2 jar maven-plugin

为了为我们的项目提供一体化Jar,我们想知道是否可以将项目生成的站点(通过站点插件生成)包含到生成的项目包中? 这背后的想法非常简单,我们有一个名为“sample”的项目,它演示了我们API的用法,我们希望在单个包中向用户提供有关API及其用法的文档。 是否可以使用Maven创建这样的Jar?

提前致谢!

3 个答案:

答案 0 :(得分:5)

使用site:jar然后使用程序集插件创建所有内容的捆绑应该是可能的。

答案 1 :(得分:3)

我发布这里是为了记录使用最近的Maven 3中包含的maven生成的站点构建war文件的解决方案。我已将所需的构建插件包装到由Hudson设置BUILD_NUMBER系统属性激活的配置文件中。除了将站点目录添加到war之外,此配置还会生成-javadoc.jar工件(具有attach-javadocs执行的单独maven-javadoc-plugin负责此操作,如果不需要,可以将其删除)。 / p>

<profiles>
    <!-- We want the javadoc jar and the site within the war only when building on Hudson -->
    <profile>
        <activation>
            <property>
                <name>BUILD_NUMBER</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.0-beta-3</version>
                    <configuration>
                        <reportPlugins>
                            <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-project-info-reports-plugin</artifactId>
                            </plugin>
                            <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-javadoc-plugin</artifactId>
                            </plugin>
                        </reportPlugins>
                    </configuration>
                    <executions> 
                        <execution> 
                            <id>attach-site</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals> 
                        </execution> 
                    </executions> 
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                        <webResources>
                            <resource>
                                <!-- this is relative to the pom.xml directory -->
                                <directory>${project.build.directory}/site</directory>
                                <targetPath>doc</targetPath>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

这是相同的配置文件,但对于Maven2。如果你有一个依赖于maven2 hudson插件的hudson项目配置,那么这很有用。

<profiles>
    <!-- We want the javadoc jar and the site within the war only when building on Hudson -->
    <profile>
        <activation>
            <property>
                <name>BUILD_NUMBER</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                        <webResources>
                            <resource>
                                <!-- this is relative to the pom.xml directory -->
                                <directory>${project.build.directory}/site</directory>
                                <targetPath>doc</targetPath>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>2.2</version>
                    <executions> 
                        <execution> 
                            <id>attach-site</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals> 
                        </execution> 
                    </executions> 
                </plugin>
            </plugins>
        </build>
        <reporting>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                </plugin>
            </plugins>
        </reporting>
    </profile>
</profiles>

答案 2 :(得分:0)

诀窍是配置maven-site-plugin以在包之前发生的阶段(例如prepare-package)生成网站,然后将生成的网站正确地包含到配置maven-war-plugin的webapp中。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-site-plugin</artifactId>
    <version>3.5</version>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>site</goal>
                <goal>stage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <webResources>
            <resource>
                <directory>${basedir}/target/staging</directory>
                <includes>
                    <include>**</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>

Here您可以使用此配置找到示例项目。 Here现场演示。