簡體   English   中英

Java 11 將 jdk.compiler/com.sun.tools.javac 類包含到項目中

[英]Java 11 include jdk.compiler/com.sun.tools.javac classes into project

我需要使用私有com.sun.tools.javac類,並且在編譯和運行時都不可見。

我用:

  • JDK 11.0.15
  • Maven 構建工具
  • Intellij IDEA

我目前的狀態是我的導入是紅色高亮並且編譯失敗。

我的班級我想在里面使用 sun 工具(對不起,圖片而不是代碼,我的班級有 2000 多行長度,現在我只關心班級中工具的可用性):

在此處輸入圖像描述

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>

我需要能夠在mvn compile期間和運行時使這些類在我“鍵入”時可用。

我想要的com.sun包:

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

先感謝您!

我能夠使用以下編譯器插件配置使其工作。

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

其他破壞我代碼的東西maven-javadoc-plugin添加到我的插件中。

Java 11 中com.sun.tools.javac包的 Javadoc說:

這個包為javac工具提供了一個舊的入口點。 有關替換 API 的詳細信息,請參閱jdk.compiler模塊。

👉 訪問模塊java.compiler ,包javax.tools ,用於接口JavaCompiler和類ToolProvider

有關示例代碼,請參閱 Javadoc。

com.sun包從來都不是標准的,從來沒有被支持過,也從來沒有打算供外部使用。

請參閱JEP 403:強封裝 JDK 內部

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM