Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 626
Ky. Avatar asked Jun 15 '15 12:06

Ky.


3 Answers

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.

like image 137
ores Avatar answered Nov 05 '22 01:11

ores


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

like image 37
Pavel Uvarov Avatar answered Nov 05 '22 01:11

Pavel Uvarov


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!

like image 1
Ky. Avatar answered Nov 05 '22 02:11

Ky.