我是靠谱客的博主 坚定棉花糖,最近开发中收集的这篇文章主要介绍Java 模块 添加,添加java 9系统模块在eclipse中编译,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

}

}

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

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.

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.

解决方案

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

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

This dialog tab combines effects of --add-modules and --limit-modules.

最后

以上就是坚定棉花糖为你收集整理的Java 模块 添加,添加java 9系统模块在eclipse中编译的全部内容,希望文章能够帮你解决Java 模块 添加,添加java 9系统模块在eclipse中编译所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(80)

评论列表共有 0 条评论

立即
投稿
返回
顶部