Issue
tl;dr
What dependency am I missing that allows NetBeans to run OS X-integrated program just fine internally, but not to be able to clean and build it to a JAR?
I'm trying to make a Java program that integrates into OS X, but I am hoping to release it onto Windows and Linux as well. To do this, I'm using the com.apple.eawt
package's utility classes.
So far, it's been great. I've got my menu bar integrated into OS X, I've got Preferences Handlers and About Handlers and all that fun stuff and it's working great... when I'm just clicking Run in NetBeans. However! When I click Clean and Build, I get many, many errors like these:
/my/source/path/MenuBarManager.java:3: error: package com.apple.eawt does not exist
import com.apple.eawt.AboutHandler;
/my/source/path/MenuBarManager.java:62: error: cannot find symbol
private static class MyAboutHandler implements AboutHandler {
^
symbol: class AboutHandler
location: class MyMenuBarManager
/my/source/path/MyMenuBarManager.java:68: error: package AppEvent does not exist
@Override public void handleAbout(AppEvent.AboutEvent ae) {
^
/my/source/path/MyMenuBarManager.java:67: error: method does not override or implement a method from a supertype <br/>
@Override public void handleAbout(AppEvent.AboutEvent ae) {
^
Why can I run it in the IDE just fine, but I can't tell the IDE to compile it to a JAR?
Attempted fix
I attempted Ajith John's fix of completely re-creating the project by making a brand new NetBeans project, copying all the source files into it, and clicking "Clean and Build". I got the same result, so this did not work.
Solution
Even though the package com.apple.eawt
is in the runtime jar rt.jar
(if on OS X), the compiler looks for the package in a symbol file called ct.sym
. The symbol file only contains the standard Java packages and not the Apple extensions.
One solution is to use the javac option -XDignore.symbol.file
as shown below. However the -XD options are non-standard and undocumented, see here and here.
A better solution may be to rewrite the code in a way that doesn't use the non-standard Apple extensions.
Answered By - ores
Answer Checked By - David Marino (JavaFixing Volunteer)