如何在项目中编译和运行我的Custom Doclet类? [英] How can I compile and run my Custom Doclet class in my project?

查看:152
本文介绍了如何在项目中编译和运行我的Custom Doclet类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在编译时将所有类javadoc注释(库WebPage类的首选子类)转储为.properties文件,其格式为classname=comment.

I'm trying to dump all class javadoc comment (preferabbly subclasses of a libraries WebPage class) at compile time into a .properties file in the format classname=comment.

到目前为止,我有:

  • 创建了doclet类SiteMapDoclet
    • 定义该类以扫描项目中的所有javadocs并将其转储到.properties文件中

    版本: Java 1.6.0.21,Maven 2.2.1

    Versions: 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)
    

    我尝试将jars设置为AdditionalDependencies,即使它们是我项目的常规依赖项. 我还尝试将路径添加到我希望班级需要的jars中,作为bootclasspath的一部分.

    I tried setting the jars as AdditionalDependencies even though they are normal dependencies for my project. I also tried adding the paths to the jars I expect my class to need as part of the bootclasspath.

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

    the reporting section of my pom.xml looks like this:

    <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;

    NOTE:
    ${m2Repository} is defined as a property higher up the file,
    defined as ${env.USERPROFILE}/.m2/repository
    ${bootClassPath} is defined as a property higher up the file,
    defined as ${env.JRE_6_HOME}\lib\rt.jar;${env.JAVA_HOME}\lib\tools.jar;

    如何修复NoClassDefFoundError?

    此外,我希望将SiteMap文件作为正常构建过程的一部分运行, 在compile之后但在package之前.

    Additionally I would like my SiteMap file to run as a part of the normal build process, after compile but before package.

    我尝试在build中定义它,但是没有创建javadoc,并且我的Doclet都看不到任何日志记录输出.

    I've tried defining this in build, but the javadoc doesn't get created and I don't see any logging output from my 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>并从<reporting>复制了<configuration>部分.

    UPDATE:
    Thanks to @ben75 's suggestion. I've removed the <reporting> section of my pom.xml and now have the process failing during build. I added <goals> and copied the <configuration> section from <reporting>.

    它仍然抛出NoClassDefFoundError,但是它发生在我想要的地方.我尝试添加:

    It's still throwing the NoClassDefFoundError but it's happening on build where I want it to. I tried adding:

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

    进入配置部分,但这没用.

    To the configuration section, but that didn't work.

    推荐答案

    基于@ ben75s的出色建议,我终于能够使它运行.
    这个工程".感觉不对,我希望看到更好的方法.

    Building upon @ben75s Excellent Advice I was able to get it to finally run.
    This "works". It feels wrong and I'd love to see a better method.

    这就是我所做的:

    • 使用Javadoc目标在build部分中定义了插件.
      • 确保tools.jar和rt.jar在<bootclasspath>
      • <docletPath>定义为\;.;${project.build.outputDirectory};
        • \;.;是必需的,因为maven不能正确附加
        • 还必须在此处明确将路径添加到某些软件包中,以防止继承冲突版本. (特别是Log4J)
        • Defined the plugin in the build section with the javadoc goal.
          • made sure tools.jar and rt.jar are in the <bootclasspath>
          • defined the <docletPath> as \;.;${project.build.outputDirectory};
            • the \;.; are necessary because maven doesn't append correctly
            • also had to explicitly add the path to some of the packages here to prevent inheritence of conflicting versions. (Specifically of Log4J)

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

            My plugin now looks like this:

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

            这篇关于如何在项目中编译和运行我的Custom Doclet类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆