简体   繁体   中英

Package from rt.jar “does not exist” when compiling with ant

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.

Don't rely on classes in "sun.", they've been removed - Oracle bought Sun a long time ago. The standard Java logger is java.util.logging.Logger

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM