Exporting a package from system module is not allowed with --release

前端 未结 5 1597
迷失自我
迷失自我 2021-01-02 03:15

I have the following program:

module-info.java

module a {
}

Main.java

public clas         


        
相关标签:
5条回答
  • 2021-01-02 03:32

    Go to the File menu -> [Settings] -> [Build, Execution, Deployment] -> [Java Compiler] and select your JDK version. (Make sure it is higher than JDK 11)

    See the image below

    0 讨论(0)
  • 2021-01-02 03:35

    If you are using InetlliJ Idea do this setting: Go to the File menu -> [Settings] -> [Build, Execution, Deployment] -> [Java Compiler] and select your JDK version and sometimes this is empty so insert the java version like [if you use 11] and save, Then compile the program and run.

    0 讨论(0)
  • 2021-01-02 03:37

    If you are using IntelliJ idea, try checking your Java compiler settings:

    Go to the File menu -> [Settings] -> [Build, Execution, Deployment] -> [Java Compiler] and check the setting "Project bytecode version". I got a similar error ("exporting a package from system module java.datatransfer is not allowed with --release") when using JDK 11 while this value was still set to version 9. Setting it to 11 fixed the problem for me.

    0 讨论(0)
  • 2021-01-02 03:42

    use -target & -source instead:

    -target 11 -source 11
    
    0 讨论(0)
  • 2021-01-02 03:46

    It appears from this bug ticket that --release cannot be used in combination with --add-exports, --add-reads, and --patch-module.

    From the link:

    The overall proposal here is to get make --release 9 work consistently between JDK 9 and the (anticipated) JDK 10, even at the cost of a possible different behavior of commands like:
    $ <jdk9>/javac Test.java
    $ <jdk9>/javac --release 9 Test.java

    Also:

    Which should be acceptable, given the intents of --release - allow to compile code using supported APIs for the given JDK release.

    In particular the proposal is to:

    [edit]

    -prevents use of --add-exports, -add-reads and --patch-module for system modules in combination with --release (any version)

    Here is the file diff that contains:

    exporting a package from system module {0} is not allowed with --release

    I can't comment on the rationale but from the above quote, it pertains to allowing JDK 9 to work consistently with JDK 10.

    0 讨论(0)
提交回复
热议问题