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.