Reputation: 63
I'm trying to package a java jar file on a Windows operating system such that the user doesn't have to worry about installing jre on a Mac OS. Can I just simply place a copy of the jre in the folder where the jar file resides and point the java_home environment variable to that jre so that when I double click the jar file, it knows where the jre is located if there isn't one installed on the target (Mac OS) system?
I've been looking at the following link:
https://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html
But it seems to have more to do with deploying apps through the Mac App Store. I just basically want the user to be able to click and run the java jar file without having to install JRE.
I've also looked at some links that say to use Launch4j or jPortable, but I'd rather not have to depend on 3rd party software.
How to run jar without JRE installed manually?
How do I run a JAR file in Ubuntu that was compiled on windows?
Upvotes: 0
Views: 722
Reputation: 5486
Java 14 and newer include a new tool called jpackage that creates native executables on each platform. There are tutorials available on how to use it, e.g. here. In short, something like this should work:
jpackage --input target/ \
--name MyApp \
--main-jar myApp.jar \
--main-class com.company.MyApp \
--type dmg \
--java-options '--enable-preview'
Upvotes: 4