Add Java 9 system module and compile in eclipse
I have some legacy java code, namely:
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); } }
This is not yet modular, so you need to use – add modules to compile using 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 module I am using to compile successfully:
$javac org/test/OldClass.java --add-modules=java.activation,java.xml.ws.annotation
I want to compile it in eclipse using java 9 (using oxygen. 1a) But I got to import javax Activation failed to resolve compilation errors
How do I tell the eclipse compiler to add these modules? I didn't find any hints about it in eclipse documentation
Here you can find a simple eclipse project I'm testing
Solution
Complete documentation of these functions still needs to be written, but new & notation for photon m3 (in progress) has begun The function you are looking for is in Mentioned in the opening paragraph
This dialog tab combines the effects of – add modules and – limit modules