简体   繁体   English

com.sun.tools.javadoc.Main.execute在jdk 11中运行Doclet的替代方法是什么?

[英]What is the alternative of com.sun.tools.javadoc.Main.execute to run Doclet in jdk 11?

I am using JDK 11 on Apache netbeans 10. 我在Apache netbeans 10上使用JDK 11。

The main method is depricated since java 9 and marked for a removal where there is no alternative main方法从java 9开始被删除,并标记为删除,其中没有替代方法

All of my attempts in command line ended up with 我在命令行中的所有尝试都结束了

javadoc: error - Cannot find doclet class Exception

When I try: 当我尝试:

com.sun.tools.javadoc.Main.execute (new String[]{"-doclet",TestVarElement.class.getName(),"C:\\Users\\Super3\\Documents\\NetBeansProjects\\MyProject\\src\\pk\\TestVarElement.java"});

I get: 我明白了:

javadoc: error - Doclet class pk.TestVarElement does not contain a start method

Start method is depricated and replaced by run method, the previous set up is working for java 8 and older, I want the equivalent for 9,10,11. Start方法被depricated并由run方法替换,之前的设置适用于java 8及更早版本,我希望等效于9,10,11。

I looked at the documentation for DocumentationTool and the relevent materials but I did not find a single working example. 我查看了DocumentationTool的文档和相关材料,但我没有找到一个单独的工作示例。

Is there any way we can run a Doclet/DocletEnvironment programmatically or a working example from commandline? 我们有什么方法可以以编程方式运行Doclet / DocletEnvironment或从命令行运行工作示例?

Assuming what you're trying to do is run Javadoc programatically, the jdk.javadoc module documentation describes ways to do so: 假设你要做的是以编程方式运行Javadoc, jdk.javadoc模块文档描述了这样做的方法:

javadoc 的javadoc

This module provides the equivalent of command-line access to javadoc via the ToolProvider and Tool service provider interfaces (SPIs), and more flexible access via the DocumentationTool SPI. 该模块通过ToolProviderTool服务提供程序接口(SPI)提供与javadoc的命令行访问等效,并通过DocumentationTool SPI提供更灵活的访问。

Instances of the tools can be obtained by calling ToolProvider.findFirst or the service loader with the name "javadoc" . 可以通过调用ToolProvider.findFirst或名为"javadoc"服务加载程序来获取工具的实例。

Based on your previous code, and your edit, you don't need the functionality of the DocumentationTool SPI. 根据您之前的代码和编辑,您不需要DocumentationTool SPI的功能。 The ToolProvider SPI should suffice. ToolProvider SPI应该足够了。 As mentioned in the documentation (and by @AlanBateman in the comments) you can get the ToolProvider instance using the following: 如文档中所述(以及评论中的ToolProvider ),您可以使用以下命令获取ToolProvider实例:

ToolProvider javadoc = ToolProvider.findFirst("javadoc").orElseThrow();

You then call one of the run methods with the out/err streams of your choice and the desired arguments. 然后使用您选择的out / err流和所需的参数调用其中一个run方法。 The arguments are the same you'd use for the unsupported Main.execute API you're currently using. 这些参数与您当前使用的不受支持的Main.execute API相同。

int result = javadoc.run(System.out, System.err, /* ... your args ... */);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法运行简单的doclet程序:包com.sun.javadoc不存在 - Not able to run a simple doclet program : package com.sun.javadoc does not exist 取决于Eclipse中tools.jar(Sun JDK)的com.sun.javadoc - Depending on com.sun.javadoc from tools.jar (Sun JDK) in Eclipse Mojo开发:访问javadoc com.sun.tools.javadoc.Main类 - Mojo development : access to javadoc com.sun.tools.javadoc.Main class JDK7中没有com.sun.tools.javac - No com.sun.tools.javac in JDK7 无法编译Java doclet程序,获取包com.sun.javadoc不存在 - Couldn't compile a java doclet program, getting package com.sun.javadoc does not exist Java 11 将 jdk.compiler/com.sun.tools.javac 类包含到项目中 - Java 11 include jdk.compiler/com.sun.tools.javac classes into project tools.jar 未打包到 maven package 中。 获取 java.lang.NoClassDefFoundError: com/sun/tools/javadoc/Main - tools.jar not packaged into the maven package. Getting java.lang.NoClassDefFoundError: com/sun/tools/javadoc/Main com.sun.tools.javac.Main不在类路径中 - com.sun.tools.javac.Main is not on the classpath Javadoc生成失败:ClassCastException:com.sun.tools.javadoc.ClassDocImpl无法强制转换为com.sun.javadoc.AnnotationTypeDoc - Javadoc generation failed : ClassCastException: com.sun.tools.javadoc.ClassDocImpl cannot be cast to com.sun.javadoc.AnnotationTypeDoc 在Maven安装后找不到JDK com.sun.tools - JDK com.sun.tools not found after Maven install
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM