Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I bundle a jnlp with an OSX dock icon; this no longer appears to be possible in the java preferences

Tags:

java

macos

jnlp

The option to package a JNLP as an app does not appear to exist in Oracle's JDK 7 Java Preferences page as it did in apples as stated here

OS X desktop integration with Java Web Start lets users create a local application bundle from any Java Web Start application. The Shortcut Creation setting in Java Preferences controls whether the user is prompted to create an application bundle when opening a Java Web Start application. Bundled Java Web Start applications have all of the benefits of native application bundles, which are described in “OS X Application Bundles.”

To work around this I'm using Automator to create an .app which runs a shell script that executes a JNLP. This allows me to use an app icon, but all my attempts of configuring the dock icon have failed.

I've tried creating an .icns file using iconutil and adding that to the Resources folder, then specifying the .icns file in Contents/Info.plist under the field "Icon File" but I still get the java coffee cup icon in the dock when running the app.

Another thing I've tried is passing the -Xdock:icon=icon.jpg argument to javaws but this appears to only work with regular java programs.

like image 327
Lockyer Avatar asked Oct 22 '12 14:10

Lockyer


2 Answers

I found a solution to my issue. Instead of bundling the icon in the .app file you can reference it directly in the jnlp. The JNLP Developer's guide contains a description of the icon element

icon element: Contains an HTTP URL to an image file in either GIF or JPEG format. The icons are used to represents the application

during launch when Java Web Start presents the application to the user; in the Application Manager; in desktop shortcuts. A 64x64 icon is shown during download; in the Application Manager and in desktop shortcuts a 32x32 icon is used. Java Web Start automatically resizes an icon to the appropriate size.

It doesn't explicitly mention the OSX dock there, but a quick test revealed that it does indeed put place the icon there as well.

like image 84
Lockyer Avatar answered Nov 14 '22 23:11

Lockyer


I'd recommend a different approach, which will help you with other deployment methods as well(not only jnlp).

You can use reflection in your code to add OSX specific code. I've compiled my application on windows and added the dock icon for mac.

javax.swing.ImageIcon icon = ...
Class c = Class.forName("com.apple.eawt.Application");
Method m = c.getMethod("getApplication");
Object applicationInstance = m.invoke(null);
m = applicationInstance.getClass().getMethod("setDockIconImage",  javax.swing.ImageIcon.class);
m.invoke(applicationInstance,icon);
like image 34
Sorter Avatar answered Nov 15 '22 01:11

Sorter