10

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.

Ky -
  • 30,724
  • 51
  • 192
  • 308
  • It looks like the library is on runtime classpath, but not on compile classpath which is weird. Can you provide build script and also commands use to compile or run the application? – Crazyjavahacking Jun 15 '15 at 13:05
  • @Crazyjavahacking I don't. I just use NetBeans' built-in Run and Clean And Build buttons. [Here's my NetBeans setup](http://imgur.com/a/claCN) if that helps. You can see the two buttons above, as a green right-pointing right-triangle and a broom in front of a hammer. – Ky - Jun 15 '15 at 13:36
  • **If you downvote the question, please leave a comment saying why you did so. Thank you.** – Ky - Jun 15 '15 at 13:50
  • 1
    Improved formatting and removed bold style and blockquote from tl;dr. Good question +1 – Ram Jun 18 '15 at 03:31
  • What sort of project is it? How did you create it? If you right-click the project and choose Properties, what do you see? – David P. Caldwell Jun 29 '15 at 21:30
  • @DavidP.Caldwell It's a Java Application. I created it with the New Project wizard. [This is what I see](http://i.imgur.com/OEyWR9y.jpg) – Ky - Jul 07 '15 at 12:51

3 Answers3

3

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.

ores
  • 156
  • 1
  • 9
1

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

Pavel Uvarov
  • 1,090
  • 1
  • 10
  • 16
  • Where do I get `pom.xml`? Where do I get the necessary `.jar`? How do I know if NetBeans is using Maven or ant? I use Swing for my UI, but the `eawt` for OS X menu bar integration. How can I just deploy one `jar` for all OSs, like [Dr. Java](http://www.drjava.org/download.shtml) does? – Ky - Jun 15 '15 at 13:36
  • If you use Maven - in your project's root folder you can find pom.xml file. If you use Ant - in your project's root folder you can find build.xml file. (For NetBeans - for ant it contains 2 files - build.xml as autogenerated script and some other, don't member it's name, xml with user-defined content). Please see actual samples for build tool to add dependencies in build process. – Pavel Uvarov Jun 15 '15 at 14:16
  • I ound `build.xml`, so I must be using ant. Where do I find the unnamed `.jar` you mention? Obviously it's somewhere because it can run inside the IDE... – Ky - Jun 15 '15 at 14:24
  • Now you should find what dependency you should add and add it to classpath in build.xml (please see documentation for ant). Or you can add Apache Ivy [link](http://ant.apache.org/ivy/) in your ant build and configure dependency you wish add to build process. – Pavel Uvarov Jun 15 '15 at 14:30
  • That's something I don't know. That's why I asked this question. What dependency am I missing that this won't build, but it will run? – Ky - Jun 15 '15 at 15:11
  • You asked about reason, not about google ;) Just add ui.jar from jdk to your classpath to compile. More information you can found [here](http://stackoverflow.com/questions/13978471/com-apple-eawt-what-exactly-i-should-install) – Pavel Uvarov Jun 15 '15 at 17:36
  • What do you mean 'about google'? I tried Googling this and it came up with a lot that didn't seem to apply to me, so I asked here. Where is `ui.jar`? I don't appear to have it on my mac: http://i.imgur.com/ozpKDfe.png – Ky - Jun 15 '15 at 18:24
1

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!

Ky -
  • 30,724
  • 51
  • 192
  • 308