1

我试图在编译时将所有类 javadoc 注释(最好是库 WebPage 类的子类)转储到格式为 .properties 的文件中classname=comment

到目前为止,我有:

  • 创建 doclet 类SiteMapDoclet
    • 该类被定义为扫描项目中的所有 javadocs 并将它们转储到 .properties 文件中
  • 将必要的配置添加到我的 pom.xml 以使其正常工作。

版本: Java 1.6.0.21、Maven 2.2.1

问题:
mvn site返回:

Embedded error: Error rendering Maven report: 
Exit code: 1 - java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at us.ak.state.revenue.cssd.Personnel.utils.SiteMapDoclet.<clinit>(SiteMapDoclet.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)

我尝试将 jar 设置为AdditionalDependencies即使它们是我的项目的正常依赖项。我还尝试将路径添加到我希望我的类需要作为引导类路径的一部分的 jar 中。

我的 pom.xml 的报告部分如下所示:

<reporting>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-javadoc-plugin</artifactId>
      <version>2.9</version>
      <reportSets>
        <reportSet>
          <id>html</id>
          <reports>
            <report>javadoc</report>
          </reports>
        </reportSet>
        <reportSet>
          <id>siteMap</id>
          <configuration>
            <doclet>
              us.ak.state.revenue.cssd.Personnel.utils.SiteMapDoclet
            </doclet>
            <docletPath>${project.build.outputDirectory}</docletPath>
            <destDir>SiteMap</destDir>

            <author>false</author>
            <useStandardDocletOptions>false</useStandardDocletOptions>
            <!-- there has got to be a better way to do this! -->
            <!-- how can I fix the CSSD-Web - Base to use a proper manifest file? -->
            <bootclasspath>
              ${bootClassPath};
              ${env.CLASSPATH};
              ${m2Repository}/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar;
              ${m2Repository}/org/apache/wicket/wicket-core/${wicket.version}/wicket-core-${wicket.version}.jar;
              ${m2Repository}/us/ak/state/revenue/cssd/CSSD-Web/${CSSDWebBase.version}/CSSD-Web-${CSSDWebBase.version}.jar
            </bootclasspath>
            <additionalDependencies>
              <additionalDependency>
                <groupId>us.ak.state.revenue.cssd</groupId>
                <artifactId>CSSD-Web</artifactId>
                <version>${CSSDWebBase.version}</version>
              </additionalDependency>
              <additionalDependency>
                <groupId>org.apache.wicket</groupId>
                <artifactId>wicket-core</artifactId>
                <version>${wicket.version}</version>
              </additionalDependency>
              <additionalDependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.16</version>
              </additionalDependency>
              <additionalDependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>1.1.1</version>
              </additionalDependency>
            </additionalDependencies>

            <name>SiteMapDoclet</name>
            <description>Page Descriptions for SiteMap generation</description>
          </configuration>
          <reports>
            <report>javadoc</report>
          </reports>
        </reportSet>
      </reportSets>
    </plugin>
  </plugins>
</reporting>

注意:
${m2Repository}被定义为文件上层的属性,
定义为${env.USERPROFILE}/.m2/repository
${bootClassPath}定义为文件上层的属性,
定义为${env.JRE_6_HOME}\lib\rt.jar;${env.JAVA_HOME}\lib\tools.jar;

我该如何解决NoClassDefFoundError

此外,我希望我的 SiteMap 文件作为正常构建过程的一部分compilepackage.

我已经尝试在 中定义它build,但是 javadoc 没有被创建,而且我没有看到我的 Doclet 的任何日志输出。

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.9</version>
    <executions>
      <execution>
        <id>build-siteMap-Descriptions</id>
        <phase>process-classes</phase>
      </execution>
    </executions>
  </plugin>

更新:
感谢@ben75 的建议。我已经删除了pom.xml<reporting>的部分,现在在构建过程中该过程失败了。我从. _<goals><configuration><reporting>

它仍在抛出,NoClassDefFoundError但它发生在我想要的构建位置。我尝试添加:

<includeDependencySources>true</includeDependencySources>
<dependencySourceIncludes>
  <dependencySourceInclude>org.apache.wicket:wicket-core:*</dependencySourceInclude>
  <dependencySourceInclude>org.apache.commons.logging:*</dependencySourceInclude>
  <dependencySourceInclude>us.ak.state.revenue.cssd:CSSD-Web:*</dependencySourceInclude>
</dependencySourceIncludes>

到配置部分,但这不起作用。

4

2 回答 2

1

您可以尝试将您的<additionalDependencies>as 插件依赖项:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-javadoc-plugin</artifactId>
      <version>2.9</version>
      <dependencies>
         <dependency>
            <groupId>us.ak.state.revenue.cssd</groupId>
            <artifactId>CSSD-Web</artifactId>
            <version>${CSSDWebBase.version}</version>
         </dependency>
         ...

要将 javadoc 插件附加到您的正常构建过程中,我认为您只需要指定目标并最好将其附加到 prepare-package 阶段(以便在您简单地运行测试阶段时不会生成 javadoc):

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.9</version>
            <executions>
                <execution>
                    <id>attach-javadoc</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
于 2013-02-20T21:23:59.610 回答
0

在@ben75s 的优秀建议的基础上,我终于能够让它运行起来。
这“有效”。感觉不对,我很想看到更好的方法。

这是我所做的:

  • 使用 javadoc 目标在构建部分定义插件。
    • 确保 tools.jar 和 rt.jar 在<bootclasspath>
    • 定义<docletPath>\;.;${project.build.outputDirectory};
      • \;.;是必要的,因为 Maven 没有正确附加
      • 还必须在此处显式添加某些包的路径,以防止继承冲突版本。(特别是 Log4J)
    • <docletArtifacts>用抛出的类的包定义NoClassDefFoundError

我的插件现在看起来像这样:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.9</version>
    <executions>
      <execution>
        <id>build-siteMap-Descriptions</id>
        <phase>process-classes</phase>
        <goals>
          <!--<goal>aggregate</goal>-->
          <goal>javadoc</goal>
        </goals>
        <configuration>
          <doclet>
            us.ak.state.revenue.cssd.Personnel.utils.SiteMapDoclet
          </doclet>
          <!-- the initial '\;.;' is required
               because maven doesn't separate the path statements properly

               The 5 packages are necessary
               because otherwise slf4j complains about multiple bindings
          -->
          <docletPath>
            \;.;${project.build.outputDirectory};
            ${m2Repository}/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar;
            ${m2Repository}/log4j/log4j/1.2.16/log4j-1.2.16.jar;
            ${m2Repository}/log4j/apache-log4j-extras/1.1/apache-log4j-extras-1.1.jar;
            ${m2Repository}/us/ak/state/revenue/cssd/CSSD-Web/${CSSDWebBase.version}/CSSD-Web-${CSSDWebBase.version}.jar;
            ${m2Repository}/org/apache/wicket/wicket-core/${wicket.version}/wicket-core-${wicket.version}.jar;
            ${m2Repository}/org/apache/wicket/wicket-util/${wicket.version}/wicket-util-${wicket.version}.jar;
          </docletPath>
          <docletArtifacts>
            <!--
            <docletArtifact>
              <groupId>commons-logging</groupId>
              <artifactId>commons-logging</artifactId>
              <version>1.1.1</version>
            </docletArtifact>
            -->
            <docletArtifact>
              <groupId>org.slf4j</groupId>
              <artifactId>slf4j-log4j12</artifactId>
              <version>1.6.2</version>
            </docletArtifact>
            <!-- how do I fix the download errors? -->
            <!--
            <docletArtifact>
              <groupId>org.slf4j</groupId>
              <artifactId>slf4j-api</artifactId>
              <version>1.6.2</version>
            </docletArtifact>
            -->
            <!--
            <artifact>
              <groupId>log4j</groupId>
              <artifactId>log4j</artifactId>
              <version>1.2.16</version>
            </artifact>
            -->
            <!--
            <docletArtifact>
              <groupId>log4j</groupId>
              <artifactId>apache-log4j-extras</artifactId>
              <version>1.1</version>
            </docletArtifact>
            <docletArtifact>
              <groupId>us.ak.state.revenue.cssd</groupId>
              <artifactId>CSSD-Web</artifactId>
              <version>${CSSDWebBase.version}</version>
            </docletArtifact>
            <docletArtifact>
              <groupId>org.apache.wicket</groupId>
              <artifactId>wicket-core</artifactId>
              <version>${wicket.version}</version>
            </docletArtifact>
            -->
          </docletArtifacts>

          <!-- the initial '\;.;' is required
               because maven doesn't separate the path statements properly -->
          <bootclasspath>
            \;.;
            ${bootClassPath};
            ${env.CLASSPATH};
          </bootclasspath>

          <destDir>SiteMap</destDir>

          <author>false</author>
          <!-- don't print the packages/classes it's running on -->
          <quiet>true</quiet>
          <debug>true</debug> <!-- save options -->
          <useStandardDocletOptions>false</useStandardDocletOptions>

          <name>SiteMapDoclet</name>
          <description>Page Descriptions for SiteMap generation</description>
        </configuration>
      </execution>
    </executions>
  </plugin>
于 2013-02-22T19:53:56.800 回答