在IntelliJ IDEA 2017.2.1中无法使用--patch-module编译Java 9模块 [英] cannot compile Java 9 module with --patch-module in IntelliJ IDEA 2017.2.1
问题描述
我正在尝试熟悉Java 9模块以及如何在IntelliJ中定义它们。除此之外,我想使用 - patch-module
编译器/ JVM标志来解决拆分包问题,我不知道如何使它在IntelliJ中工作。
我正在使用IntelliJ IDEA 2017.2.1使用Java HotSpot(TM)64位服务器VM构建#IC 172.3544.35(内置9 + 180,混合模式)。
这是我的源文件 MyImmutableList.java
:
package com.google.common.collect;
public class MyImmutableList extends RegularImmutableList {
public MyImmutableList(Object [] array){
super(array);
}
}
它属于我的模块 com.effjava.collect
with module-info.java
:
module com.effjava.collect {
//不需要模块番石榴;而是使用guava.19-0.jar修补此模块:
// javac --patch-module com.effjava.collect = guava-19.0.jar module-info.java com / google / common / collect / MyImmutableList.java
//需要guava;
导出com.google.common.collect;
}
为了编译我的模块,我指定了 IntelliJ中使用
设置
=> 构建,执行,深层次
编译器
=> 共享构建过程VM选项
as
- O verride编译器参数每模块
- 选择模块
-
将编译选项添加到补丁( 注意 - 我使用了最新版本的jar )
- patch-module com.effjava .collect = / Users / naman.nigam / .m2 / repository / com / google / guava / guava / 24.1-jre / guava-24.1-jre.jar
发布此选择 构建>构建项目 并且构建成功完成(尽管我仍然在 MyImmutableList
中看到 RegularImmutableList
为红色)我。
I am trying to acquaint myself with Java 9 modules and how to define them in IntelliJ. Among other things, I want to solve a split package problem using the --patch-module
compiler/JVM flag and I don't know how to make it work in IntelliJ.
I am using IntelliJ IDEA 2017.2.1 Build #IC 172.3544.35 with Java HotSpot(TM) 64-Bit Server VM (build 9+180, mixed mode).
This is my source file MyImmutableList.java
:
package com.google.common.collect;
public class MyImmutableList extends RegularImmutableList {
public MyImmutableList(Object[] array) {
super(array);
}
}
It belongs to my module com.effjava.collect
with module-info.java
:
module com.effjava.collect {
// do not require module guava; instead patch this module with guava.19-0.jar via:
// javac --patch-module com.effjava.collect=guava-19.0.jar module-info.java com/google/common/collect/MyImmutableList.java
// requires guava;
exports com.google.common.collect;
}
For the compilation of my modules, I specified the --patch-module
flag in IntelliJ using Settings
=> Build,Execution,Deplyoment
=> Compiler
=> Shared build process VM options
as described here.
The compilation fails because the compiler cannot find the superclass RegularImmutableList
from the guava library.
The advice provided by IntelliJ is to add a requires
directive for the guava library to the module descriptor, which of course does not work because the compiler then rightly complains about the split package problem:
Error:java: module guava reads package com.google.common.collect from both com.effjava.collect and guava
On further investigation, I noticed that the build process issues a warning related to the --patch-module
flag saying:
Error:Abnormal build process termination: "C:\Program Files\Java\jdk-9\bin\java" -Xmx700m -Djava.awt.headless=true
... lots of stuff ...
WARNING: Unknown module: com.effjava.collect specified to --patch-module
... more stuff ...
BTW, I did not know how to get hold of the compiler warnings. I do not hide them in IntelliJ's message window and yet I cannot see them. As a workaround, I simply specified bogus compiler flags and let the build process crash so that it emitted the WARNING in its crash report.
Anyway, the build process complains - while building the module - that the module in question does not exist and for this reason cannot be patched via --patch-module
. This complaint does not make sense because I did successfully compile and build my module by typing in the javac
and jar
commands manually on the command line level:
cd %PROJECTDIR%\com.effjava.collect\src
javac --patch-module com.effjava.collect=../../guava/guava-19.0.jar -d ../../out/production/com.effjava.collect module-info.java com/google/common/collect/MyImmutableList.java
jar --create --file=../../out/artifacts/com_effjava_collect_jar/com.effjava.collect.jar -C ../../out/production/com.effjava.collect .
How can I tell IntelliJ's build process that I want to patch my module?
Well eventually with the following configuration of the IntelliJ(Fix version of IDEA-169150) -
IntelliJ IDEA 2018.1 (Community Edition) Build #IC-181.4203.550, built on March 27, 2018 JRE: 1.8.0_152-release-1136-b20 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.13.3
and the Java Compiler settings for the project as the one in the following screenshot:-
- Override compiler paramaters per-module
- Select the module
Add the compilation option to patch (Note - I've used the latest version of the jar)
--patch-module com.effjava.collect=/Users/naman.nigam/.m2/repository/com/google/guava/guava/24.1-jre/guava-24.1-jre.jar
Post this select Build > Build Project and the build completes successfully(though I still see RegularImmutableList
in MyImmutableList
as red) for me.
这篇关于在IntelliJ IDEA 2017.2.1中无法使用--patch-module编译Java 9模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!