简体   繁体   English

Java 11 将 jdk.compiler/com.sun.tools.javac 类包含到项目中

[英]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:我用:

  • JDK 11.0.15 JDK 11.0.15
  • Maven build tool Maven 构建工具
  • Intellij IDEA Intellij IDEA

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

  • com.sun.tools.javac.code com.sun.tools.javac.code
  • com.sun.tools.javac.comp com.sun.tools.javac.comp
  • com.sun.tools.javac.file com.sun.tools.javac.file
  • com.sun.tools.javac.main com.sun.tools.javac.main
  • com.sun.tools.javac.model com.sun.tools.javac.model
  • com.sun.tools.javac.parser com.sun.tools.javac.parser
  • com.sun.tools.javac.processing com.sun.tools.javac.processing
  • com.sun.tools.javac.tree com.sun.tools.javac.tree
  • com.sun.tools.javac.util com.sun.tools.javac.util

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.

相关问题 JDK7中没有com.sun.tools.javac - No com.sun.tools.javac in JDK7 环境(在模块 jdk.compiler 中),因为模块 jdk.compiler 不会将 com.sun.tools.javac.processing 导出到未命名的模块 - Environment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module 模块 jdk.compiler 不会“打开 com.sun.tools.javac.processing” - module jdk.compiler does not "opens com.sun.tools.javac.processing" Java, Intellij IDEA 问题 Unrecognized option: --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED - Java, Intellij IDEA problem Unrecognized option: --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED 模块 jdk.compiler 不会“打开 com.sun.tools.javac.processing”到未命名的模块 @4bae33a6 - module jdk.compiler does not “opens com.sun.tools.javac.processing” to unnamed module @4bae33a6 JDT编译器中的com.sun.tools.javac.jvm.ClassWriter等效项 - com.sun.tools.javac.jvm.ClassWriter equivalent in JDT compiler java.lang.NoClassDefFoundError:com / sun / tools / javac / Main - java.lang.NoClassDefFoundError: com/sun/tools/javac/Main 从 Java 9 访问 com.sun.tools.javac.util - Accessing com.sun.tools.javac.util from Java 9 Unable to find a javac compiler com.sun.tools.javac.Main is not on the classpath 错误 - Unable to find a javac compiler com.sun.tools.javac.Main is not on the classpath error 编译器错误 - “错误:无法找到或加载主类 com.sun.tools.javac.Main” - Compiler Error - 'Error: Could not find or load main class com.sun.tools.javac.Main'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM