添加java 9系统模块在eclipse中编译 [英] add java 9 system modules to compile in eclipse
问题描述
我有一些遗留Java代码,即:
I have some legacy Java code, ie.:
package org.alo.test.j9;
import javax.activation.DataHandler; // in java.activation module
import javax.annotation.PostConstruct; // in java.xml.ws.annotation module
public class OldClass {
public static void main(String[] args) {
DataHandler dh = new DataHandler(null, null);
System.out.println(dh);
}
}
尚未模块化,因此需要使用 - add-modules
用Java 9编译它。
That is not yet modularized so it requires to use --add-modules
to compile it with Java 9.
$ javac -version
javac 9
$ javac org/alo/test/j9/OldClass.java
src/org/alo/test/j9/OldClass.java:3: error: package javax.activation is not visible
import javax.activation.DataHandler; // in java.activation module
^
(package javax.activation is declared in module java.activation, which is not in the module graph)
src/org/alo/test/j9/OldClass.java:4: error: package javax.annotation is not visible
import javax.annotation.PostConstruct; // in java.xml.ws.annotation module
^
(package javax.annotation is declared in module java.xml.ws.annotation, which is not in the module graph)
2 errors
我需要添加我正在使用的模块才能成功编译:
I need to add the modules I'm using in order to be able to successfully compile:
$ javac org/test/OldClass.java --add-modules=java.activation,java.xml.ws.annotation
我想在Eclipse中使用Java 9编译它(使用Oxygen.1a)但是我得到无法解析导入javax.activation
编译错误。
I want to compile it in Eclipse (using Oxygen.1a) with Java 9. But I get The import javax.activation cannot be resolved
compilation error.
如何告诉eclipse编译器添加这些模块?我没有在 Eclipse文档中找到任何关于它的提示。
How can I tell the eclipse compiler to add these modules? I didn't find any tip in Eclipse documentation about it.
这里你可以找到一个简单的日食项目我'使用。进行测试。
Here you can find a simple eclipse project I'm testing with.
推荐答案
仍然需要编写这些功能的完整文档,但是在 New&值得注意的是Photon M3 (正在进行中)。您要查找的功能在以
Complete documentation for these features still needs to be written, but a start has been made in the New & Noteworthy for Photon M3 (work in progress). The functionality you are looking for is mentioned in the paragraph starting with
在内容选项卡中,JRE系统库等容器内的各个模块可以是通过从左到右移动模块来包含或排除,反之亦然...
On the Contents tab individual modules inside a container like JRE System Library can be included or excluded by moving the module from left-to-right or vice versa ...
此对话框选项卡结合<$的效果c $ c> - add-modules 和 - limit-modules
。
This dialog tab combines effects of --add-modules
and --limit-modules
.
这篇关于添加java 9系统模块在eclipse中编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!