0

I was trying to improve logging of my HTTP connections by using the built-in java.util.logging features. But after inserting a line to activate the logging in the code, i'm getting an error in my ant build that i do not understand.

error: package sun.util.logging does not exist
    import sun.util.logging.PlatformLogger;
           ^

sun.util.logging.PlatformLogger is located in rt.jar which should always be on the classpath as far as i know. And it's not an "internal API" that would throw a warning during compilation. The code works fine in Eclipse.

Ant is running on JDK 1.8.0_60 as is my Eclipse project. I expect it to use the rt.jar from that installation. Why can it not access some select classes? Or am i looking at the wrong set of core classes and the javac task is using a different rt.jar?

Sidenote: i know that i can use logging properties to set it up. That's not the point of this question. I want to know why ant is having a problem that Eclipse doesn't.

Stroboskop
  • 4,327
  • 5
  • 35
  • 52
  • I'm starting to think that "someone" removed all the access restrictions on rt.jar in my Eclipse workspace and that i should never have been able to access `PlatformLogger` in the first place. But the question remains, how does javac know what classes may not be referenced by code? – Stroboskop Jun 28 '17 at 16:54
  • Eclipse does not use `javac`. They have their own compiler. – Elliott Frisch Apr 30 '20 at 18:59

1 Answers1

0

This question explains my problem.

In short: javac doesn't actually compile against rt.jar. Instead it uses jdk/lib/ct.sym which contains most classes as stubs, but e.g. not PlatformLogger. There's a VM parameter to deactivate it, but that's of course not encouraged.

Eclipse on the other hand is using ct.sym as a friendly suggestion that you can throw out the window if you like to code like my co-workers.

Stroboskop
  • 4,327
  • 5
  • 35
  • 52