Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Bundling .jar files to .app in Mavericks?

So I just updated to Mavericks like everyone else because it's free. However I am a Java developer and I would like to bundle my .jar files into a Mac executable. However, a few things have changed with Mavericks, as with all updates to OS X. For one thing, there's no /usr/share/ant/ directory. There's /usr/share/, but not an ant/ folder.


So my point is this: do you know of a good updated site that shows jar bundling?

MacBook Pro, OS X Mavericks (10.9), Model of 2008

Posted on Oct 23, 2013 8:26 PM

Reply
Question marked as Best reply

Posted on Mar 27, 2014 12:53 AM

This is how I managed to do it. I use NetBeans to compile to a .jar file. You also need to have the Java jdk1.7.0_45.jdk installed.


A) Download apache-ant-1.9.3-bin.tar.gz from http://ant.apache.org/bindownload.cgi to your Downloads folder


B) In the terminal do the following (taken with some changes from http://stackoverflow.com/questions/3222804/how-can-i-install-apache-ant-on-mac-o s-x)


cd ~/Downloads # Let's get into your downloads folder.

tar -xvzf apache-ant-1.9.3-bin.tar.gz # Extract the folder

sudo mkdir -p /usr/local # Ensure that /usr/local exists

sudo cp -rf apache-ant-1.9.3 /usr/local/apache-ant # Copy it into /usr/local

# Add the new version of Ant to current terminal session

export PATH=/usr/local/apache-ant/bin:"$PATH"

# Add the new version of Ant to future terminal sessions

echo 'export PATH=/usr/local/apache-ant/bin:"$PATH"' >> ~/.profile


C) Get appbundler-1.0.jar from http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.h tml


There is some good detailed information there also about bundling.You may need to set your JAVA_HOME parameter.


D) Then comes the bundling procedure:


1) Compile your source code to get a .jar file in the dist folder.

2) Make a bundle file or if you use Netbeans, edit the file build.xml in the top project folder.


<taskdef name="bundleapp"

classname="com.oracle.appbundler.AppBundlerTask"

classpath="lib/appbundler-1.0.jar" />


<target name="bundle">

<bundleapp outputdirectory="dist"

name="MySourceName"

displayname="MySourceName"

identifier="package.MySourceName"

mainclassname="package.MySourceName">

<classpath file="dist/MySourceName.jar" />

<option value="-Dapple.laf.useScreenMenuBar=true"/>

</bundleapp>

</target>


Edit the above text in some simple text editor and exchange MySourceName with your project name and “package” with your package name. The line <option value="-Dapple.laf.useScreenMenuBar=true"/> will make your menu be placed in the Mac style.

Note! Beware of the difference “ and ". The corrrect one is the latter. TextEdit changed my hyphens to the bad ones which screwed up the bundling..


The edited file should reside in the top project folder under the name build.xml.


3) Place the appbundler-1.0.jar in a new “lib” folder in the top project folder.


4) Run terminal . Go to your Netbeans project folder using the cd command. The do


ant bundle


and wait for BUILD SUCCESSFUL


The bundled Mac application will reside in the dist folder.


How to fix a specific icon to the application:


5) Open the bundled Mac application by CTRL-click and choose “Show Package Contents”


6) Double-click the Contents folder to open it. Put your tailor-made application icon “XXX.icns” in the Resources folder. Open the Info.plist and change Generic.icns to XXX.icns. Close the application folders. Sometimes the icon will only show up afterf you copy the application to another folder


Optional (This will make your application very big as it includes the Java jdk in the application, I didn't do this step. The only advantage is that it will make the application independent on the user having Java installed.a )

7) To include the jdk, open the app folder and put a copy of the jdk1.7.0_45.jdk in the Plugins folder.


Edit the Info.plist by adding a new child: JVMRuntime containing a string, jdk1.7.0_45.jdk

2 replies
Question marked as Best reply

Mar 27, 2014 12:53 AM in response to iTryFreeApps

This is how I managed to do it. I use NetBeans to compile to a .jar file. You also need to have the Java jdk1.7.0_45.jdk installed.


A) Download apache-ant-1.9.3-bin.tar.gz from http://ant.apache.org/bindownload.cgi to your Downloads folder


B) In the terminal do the following (taken with some changes from http://stackoverflow.com/questions/3222804/how-can-i-install-apache-ant-on-mac-o s-x)


cd ~/Downloads # Let's get into your downloads folder.

tar -xvzf apache-ant-1.9.3-bin.tar.gz # Extract the folder

sudo mkdir -p /usr/local # Ensure that /usr/local exists

sudo cp -rf apache-ant-1.9.3 /usr/local/apache-ant # Copy it into /usr/local

# Add the new version of Ant to current terminal session

export PATH=/usr/local/apache-ant/bin:"$PATH"

# Add the new version of Ant to future terminal sessions

echo 'export PATH=/usr/local/apache-ant/bin:"$PATH"' >> ~/.profile


C) Get appbundler-1.0.jar from http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.h tml


There is some good detailed information there also about bundling.You may need to set your JAVA_HOME parameter.


D) Then comes the bundling procedure:


1) Compile your source code to get a .jar file in the dist folder.

2) Make a bundle file or if you use Netbeans, edit the file build.xml in the top project folder.


<taskdef name="bundleapp"

classname="com.oracle.appbundler.AppBundlerTask"

classpath="lib/appbundler-1.0.jar" />


<target name="bundle">

<bundleapp outputdirectory="dist"

name="MySourceName"

displayname="MySourceName"

identifier="package.MySourceName"

mainclassname="package.MySourceName">

<classpath file="dist/MySourceName.jar" />

<option value="-Dapple.laf.useScreenMenuBar=true"/>

</bundleapp>

</target>


Edit the above text in some simple text editor and exchange MySourceName with your project name and “package” with your package name. The line <option value="-Dapple.laf.useScreenMenuBar=true"/> will make your menu be placed in the Mac style.

Note! Beware of the difference “ and ". The corrrect one is the latter. TextEdit changed my hyphens to the bad ones which screwed up the bundling..


The edited file should reside in the top project folder under the name build.xml.


3) Place the appbundler-1.0.jar in a new “lib” folder in the top project folder.


4) Run terminal . Go to your Netbeans project folder using the cd command. The do


ant bundle


and wait for BUILD SUCCESSFUL


The bundled Mac application will reside in the dist folder.


How to fix a specific icon to the application:


5) Open the bundled Mac application by CTRL-click and choose “Show Package Contents”


6) Double-click the Contents folder to open it. Put your tailor-made application icon “XXX.icns” in the Resources folder. Open the Info.plist and change Generic.icns to XXX.icns. Close the application folders. Sometimes the icon will only show up afterf you copy the application to another folder


Optional (This will make your application very big as it includes the Java jdk in the application, I didn't do this step. The only advantage is that it will make the application independent on the user having Java installed.a )

7) To include the jdk, open the app folder and put a copy of the jdk1.7.0_45.jdk in the Plugins folder.


Edit the Info.plist by adding a new child: JVMRuntime containing a string, jdk1.7.0_45.jdk

Mar 27, 2014 6:25 AM in response to labangi

labangi, it has been a long time since I've written this post and I discovered the exact same way of doing the discussed procedure, here at this link: http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.h tml


The only problem I had with that way was gettig ant permanantly installed, I forgot what I did, but somehow I have ant installed.


And I already knew about changing the app icon since I had been a Cocoa developer for the Mac back when Lion first came out.


TextEdit automatically converts the double quotes. NetBeans doesn't do that so you can use it to edit your build.xml. TextWrangler doesn't convert it either.

Bundling .jar files to .app in Mavericks?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.