Why is NetBeans running my program on OS X, but not building it into a JAR?

1.5k views Asked by At

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.

3

There are 3 answers

0
ores On BEST ANSWER

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.

enter image description here

A better solution may be to rewrite the code in a way that doesn't use the non-standard Apple extensions.

7
Pavel Uvarov On

NetBeans have hard-organized run-function. If I got it right - this function compile and run your application in NetBeans process (and its classpath). To resolve problem with compile by "build" command you should ensure that your build-agent have all necessary dependencies:

  • For Maven - you should just add dependency in pom.xml,
  • For ant - you should specify classpath to add necessary .jar into it.

PS package com.apple.eawt is Apple only package. If you wish start application on other platforms you should use simple AWT (not Apple EAWT) or other common UI framework (ex. Swing).

0
Ky - On

My current workaround is to clean-and-run the program (not build), and then place the .class files into a .zip folder with a properly-formatted META_INF folder and manifest.MF file. Then I rename the .zip extension to .jar, and use this hacked-together jarfile!