Convert .jar to an OSX executable? - java

I made a Java application which I would like to distribute on Windows, OSX and Linux without distributing a jar file. I used the great Windows exe wrapper http://launch4j.sourceforge.net/ to create an .exe file complete with my icon that won't scare Windows users.
Are there similar wrappers that I can use for OSX/Unix? An important consideration is that I would like to have my own icon on the executable (especially for mac users).
Thanks!

Yes, on Mac OS X there is a program called Jar Bundler that is installed when you install the free (assuming that you already own a copy of Mac OS X) Xcode Developer Tools that allows you to bundle a JAR file inside a native Mac OS X "*.app" application bundle with a nice and shiny icon just like other apps.
Update
The JAR bundler doesn't exist on later versions of OS X. As a workaround, you can manually create an OS X project that invokes Java. Or, there are a variety of build system extensions that do a similar thing; for example, the gradle-macappbundle plugin for Gradle will create such a wrapper app.

JarBundler is obsolete, but there is a (better) official replacement: the javapackager tool.
For OSX, A simple, well explained, step by step tutorial on how to create a DMG from java is here: http://centerkey.com/mac/java/ . For other platforms, you just need to modify the example by using the proper switches in javapackager.

If you do not have a Mac to build this on (or want to integrate it into an existing build chain), you might want to have a look at the OS X Application Bundle Plugin for Maven.
This will (if run on Linux or Windows) create a zip that will unzip as a proper Mac application. If you run Maven on a Mac, it can also make a DMG.

You can also package your application with the JarBundler Ant task:
http://informagen.com/JarBundler
<jarbundler dir="release"
name="MyApp"
mainclass="org.foo.myapp.Main"
jar="myapp.jar" />

Github user Jorl17 made an excellent Python script called jar2app that does this with one simple command. It even lets you customize the app icon.
https://github.com/Jorl17/jar2app
Just install it, follow the instructions, and you get the .app file.

Related

Run a Java application on a Mac

i am currently developing an application on my Windows laptop however I also need it to run on a Mac. Is there a way to either convert my project to .dmg or .app or create a mac build striaght from Windows Eclipse?
I would very much rather not have to install Eclipse on the Mac machine just for this as it is a one time thing. Any Suggestions?
In my experiences you need a Mac to create anything for the Mac/iOS platform. So I guess you need a mac to create a dmg file.
Here is a post that says how this can be accomplished.
Of course you can just run the jar from the command line.
run on any Java virtual machine. It does not matter if you run it on a mac or pc, that's the whole idea with java
Any simple way of creating a dmg file will probably require a Mac, however you don't need to do that; after all, you don't create an exe when you run a Java program on Windows either. Instead export it as a jar file and it should work on both systems (provided a Java Runtime Environment is installed and is set to run jar filed).
If you insist on creating a dmg, check this question which discusses creating them on Windows.

How can I build a Mac OS X .app from an eclipse program

My program works fine in Eclipse. However, if I try to export it as a runnable jar, the jar doesn't open when I double click it. Is there a way, in Eclipse, to export directly to a .app?
The gradle-macappbundle plugin is the easiest way I know how to do this. It hooks into your build system and generates the .app for you.
If you want to roll your own solution, Appleā€™s Java Deployment Options for OS X gives you all the information you need to know about doing this. Basically a .app is just a folder containing a JAR, with some XML files giving the classpath and so on. You can read that guide for all the details.
No. Apps contain a lot of other stuff. If you want the jar to run, you have to setup something to tell it to be opened by the JRE. Wouldn't recommend that.
There are (at least) two separate Ant tasks that can take a JAR file and associated resources and build a .app bundle. The appbundler task from java.net produces .app bundles that run on the Oracle Java 7 JRE and the jarbundler task produces bundles that run on the Java 6 supplied by Apple. But neither task will produce a .app that can run on both Java 6 and 7 because Oracle (7) and Apple (6) Javas use fundamentally different APIs for spawning the JVM from the launcher stub in the .app. If you want to be able to release your Java app to the Mac App Store then you have to use Java 7 and embed a copy of the JRE in the .app bundle (which appbundler can do for you). Conversely, if you want your app to be runnable on Mac OS X version 10.6 or earlier then you need to use Java 6.
Your comment on one of the other answers suggests that your app requires a native library. You need to put this library inside the .app bundle along with your JAR. The .jnilib needs to go in Contents/Resources/Java for a Java 6 bundle (the same place as the JAR file), for a Java 7 bundle you specify the library in the <librarypath> fileset and it will be copied to the right place by appbundler (Contents/MacOS).
When you export you must choose Runnable Jar File and then it will run when you double click it.

Setup file for application using QT Jambi

I want to use QT Jambi for GUI (Java project). The GUI needs to have animations (similar to Iphone apps). That is why, I do not want to use Java Swing.
My question is, after I develop the application, is there any automatic mechanism which would create a setup file which could be used to install my application in any computer (may be separate "setup" files for separate OS). In other words, I would like my users to download just one file: setup.exe. This should install the app in their computer.
I know there is one such app for .jar files (I forgot the name). But QT is a C++ library and I do not like bothering the users, asking them to download QT just to use my app.
I presume you are tagetting win32 only on the desktop and looking for free/open tools. With no response to this questio so far I thought I'd provide some info towards this point even if it is not the answer you really want.
I have been looking over the QtJambi ecosphere for the past couple of years and I'm not aware of such a tool to provide you with a process to follow that results in an EXE. There are all kinds of caveats.
The task:
Ensure the JRE5+ is installed on target system.
Ensure QtJambi files and perform things like extraction of native JAR.
Ensure QtJambi pre-reqs are installed on the target system (such as MSVCxxxx runtimes).
Finally install your application and fixup the startup configuration to make use of information above.
Setup desktop fo reasy access (Program Group, Desktop Icon, Menu items, Shortcuts)
You will find that NSIS http://nsis.sourceforge.net/ can be a tool to get some parts of the process and maybe provide a framework to write modules for NSIS that do other parts of the work. But I have found NSIS somewhat lacking when you step outside of a simple unzip of data and setup of desktop install process.
Another solution for you would be to simply provide everything that works in one ZIP file, this would include a copy of the Java JRE embedded, a copy of QtJambi embedded, the rest of your JAR and then write a toplevel *.BAT file to setup %PATH% and other arguments to run your supplied java.exe against your application. Obviously now the JRE is not likely to get updated so at some point will be considered insecure.
NSIS isn't the only such windows installer that exist.
Maybe there is a fully automatic one click install wrapper with custom parts to help setting up QtJambi, but I doubt it at this time.
Good question, and one good attempt at an answer.
I've gone down a slightly different route: embed the Qt Jambi libraries, but not a JRE. I have some basic sh/bat launch scripts which configure the resources required and am using IzPack for the installer (though NSIS might be a good alternative).
Problem: how to find the JRE
Solution: the IzPack installer needs a JRE to run, so guarantees the availability of one. It can update a variable in scripts during installation.
Solution (Windows): use the registry
Last resort: use the path
The ideal would be to integrate all three into a batch file. Anyone done this?
Problem: Qt & Qt Jambi libraries
Solution: distribute with your application and link from the shell/batch file.
The problem with this is how to make sure your libraries get used when binary-incompatible Qt libraries are already installed on the system. On Linux, extracting the libraries and exporting LD_LIBRARY_PATH seems to work. On Windows I haven't solved this and on the Mac I haven't tried.
Problem: most appropriate Qt libraries
32-bit Qt libraries probably won't work with a 64-bit JRE; this is a problem I haven't yet had to deal with. Probably the best solution would be to include both 32-bit and 64-bit Qt libraries and select between them from a script at run-time (or possibly install-time).
Another issue is related to themes: Qt has support for using native themes, but only from the platforms it's compiled on. Thus, compiling Qt on an old Windows version and using the libraries on a modern version of Windows seems to work but results in ugly Windows-98-esque widgets. The easiest solution seems to be to launch with -style Plastique (or cleanlooks) to get nicer-looking widgets.

Is it possible to convert a jar to exe using Ant build in Linux?

I have created an project and need to distribute it over Windows. I need to create an exe for it I already know that there is a lot of tools like:
JSmooth
Launch4J
Executor
Advanced Installer etc.
The installer windows are done in Java itself. Means like the selecting locations, licensing etc. the only thing I need is to create an exe that should open this jar. Is that possible in Linux?
For a Java app. with a GUI, Java Web Start is the best option. It is supplied and maintained by the maker of the JRE, and therefore works on Windows, *nix and Mac.
I do understand the need for an .exe on Windows and I've used JSmooth before.
I would just make a shell script which launches the program. I think a shell script is fine for Linux: icons aren't built into the executable and you can't discover the location of a usable JVM automatically.

using packagemaker on mac os

i want to make the installation package on the mac os of my java application using the package maker. is there any one having the link that will show step by step guidance for performing this.
See Java Deployment Options for Mac OS X on the Apple Developer site. Here's an ant build.xml file with targets to compose a Mac application bundle and create a .dmg disk image. Alternatively, consider using Java Web Start, also supported by that project.

Categories