[英]Java 11 include jdk.compiler/com.sun.tools.javac classes into project
I need to work with com.sun.tools.javac
classes that are private and are not visible neither during compile nor run time.我需要使用私有的
com.sun.tools.javac
类,并且在编译和运行时都不可见。
I use:我用:
My current state is that my imports are red-highlghited and compilation fails.我目前的状态是我的导入是红色高亮并且编译失败。
My class I want to use sun tools inside (sorry for the pic instead of code, my class is 2000+ lines length, for now I only care about availability of tools in my class):我的班级我想在里面使用 sun 工具(对不起,图片而不是代码,我的班级有 2000 多行长度,现在我只关心班级中工具的可用性):
pom.xml : pom.xml :
...
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I need to be able to have these classes available as I "type", during mvn compile
and in runtime.我需要能够在
mvn compile
期间和运行时使这些类在我“键入”时可用。
com.sun
packages I'd like to have:我想要的
com.sun
包:
Thank you in advance!先感谢您!
I was able to make it work with the following compiler plugin configuration.我能够使用以下编译器插件配置使其工作。
<compilerArgs>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
</compilerArgs>
And other thing that broke my code was maven-javadoc-plugin
added to my plugins.其他破坏我代码的东西是
maven-javadoc-plugin
添加到我的插件中。
The Javadoc for package com.sun.tools.javac
in Java 11 says: Java 11 中
com.sun.tools.javac
包的 Javadoc说:
This package provides a legacy entry point for the javac tool.
这个包为javac工具提供了一个旧的入口点。 See the
jdk.compiler
module for details on replacement APIs.有关替换 API 的详细信息,请参阅
jdk.compiler
模块。
👉 Access the module java.compiler
, package javax.tools
, for the interface JavaCompiler
and class ToolProvider
. 👉 访问模块
java.compiler
,包javax.tools
,用于接口JavaCompiler
和类ToolProvider
。
See the Javadoc for example code.有关示例代码,请参阅 Javadoc。
The com.sun
package was never standard, never supported, and never intended for external use. com.sun
包从来都不是标准的,从来没有被支持过,也从来没有打算供外部使用。
See JEP 403: Strongly Encapsulate JDK Internals .请参阅JEP 403:强封装 JDK 内部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.