[英]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.
该模块通过ToolProvider和Tool服务提供程序接口(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.