Community
Participate
Working Groups
4.7.1a. package p; import javax.annotation.Resource; public class HelloWorld { public static void main(String[] args) { Class<Resource> annoClazz = Resource.class; System.out.println(annoClazz); System.out.println("Hello World!"); } } This compiles with JavaSE-1.8 but not with JavaSE-9.
Compile error is: The import javax.annotation.Resource cannot be resolved
I tried to fix it manually, but no luck: I was able to specify the system library under the classpath node, but after reopening the Java Build Path dialog, the library is again under the module node.
Why do you expect this to work? JavaSE-9 is modular, and I don't see anything in JEP 261 that would allow putting the system library on the classpath. "Compatibility" is achieved solely via the unnamed module. With this, compile errors in previously OK programs are to be expected, in particular, JavaSE-9 does not provide access to type javax.annotation.Resource out of the box. To make it accessible to the unnamed module you need to add-module java.xml.ws.annotation. JRE System Library > Is modular > Edit ... > Contents > Move javax.xml.ws.annotation from left to right. Re-compile and all is fine. (Yes, this should be documented in places ...)
(In reply to Stephan Herrmann from comment #3) > Why do you expect this to work? Well, API compatibility? ;-) But I agree this is not "our" bug. > (Yes, this should be documented in places ...) I think even better would be a quick fix that finds and adds the module. WDYT?
Two issues on our side: - It is pretty hidden under the 'Is modular' node - It's unexpected that I can add JavaSE-9 under classpath and then it gets moved to the module path without telling me. We should prevent that already at the beginning. Good news is that we keep the module info and don't loose it if the user goes to 1.8 and back to 9.
(In reply to Dani Megert from comment #4) > (In reply to Stephan Herrmann from comment #3) > > (Yes, this should be documented in places ...) > > I think even better would be a quick fix that finds and adds the module. > WDYT? bug 526277 (In reply to Dani Megert from comment #5) > Two issues on our side: > - It is pretty hidden under the 'Is modular' node As this node is important for several tasks, I hope users well get used to it. The only improvement I could think of right now: Place a new button/link into the Edit Library dialog, from where you can switch to the ModuleDialog. > - It's unexpected that I can add JavaSE-9 under classpath and then it gets > moved to the module path without telling me. We should prevent that already > at the beginning. Bug 526275
(In reply to Stephan Herrmann from comment #6) Thank you :-)
Verified for 4.7.2