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

TL; DR

What dependency am I missing, which allows NetBeans to run the program integrated with OS X just fine inside, but not clear and create it in the JAR?


I am trying to make a Java program that integrates into OS X, but I hope to release it also on Windows and Linux. For this, I use the utility classes of the com.apple.eawt package.

So far it was great. I have a menu bar built into OS X, I have settings handlers and about handlers and all these funny things, and it works fine ... when I just click Run in NetBeans. But! When I click Clean and Build , I get many, many such errors:

 /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 say that the IDE needs to compile it into a JAR?


Attempt to fix

I tried to completely fix the Ajith John project by creating a new NetBeans project, copying all the source files into it and clicking "Clear and Build". I got the same result, so this did not work.

+8
java cross-platform netbeans macos
source share
3 answers

Although the com.apple.eawt package is located at rt.jar jar rt.jar (if on OS X), the compiler looks for the package in a character file named ct.sym . The symbol file contains only standard Java packages, not Apple extensions.

One solution is to use the javac -XDignore.symbol.file , as shown below. However, the -XD options are non-standard and undocumented, see here and.

enter image description here

A better solution would be to rewrite the code in such a way so as not to use custom Apple extensions.

+1
source share

NetBeans has a tightly organized launch feature. If I understood correctly, this function compiles and runs your application in the NetBeans process (and its class path). To solve the compilation problem with the "build" command, you must make sure that your build agent has all the necessary dependencies:

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

PS package com.apple.eawt is just an Apple package. If you want to run the application on other platforms, you must use a simple AWT (not Apple EAWT) or other common user interface interfaces (e.g. Swing).

0
source share

My current workaround is to clean up and run the program (not build) and then put the .class files in the .zip folder with the properly formatted META_INF and manifest.MF META_INF . Then I will rename the .zip extension to .jar and use this hacked jarfile!

0
source share

All Articles