如何打包Java jar文件以在未安装JRE的Mac上运行? [英] How do I package a java jar file to run on a Mac without JRE installed?

查看:185
本文介绍了如何打包Java jar文件以在未安装JRE的Mac上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows操作系统上打包Java jar文件,以使用户不必担心在Mac OS上安装jre.我可以简单地将jre的副本放置在jar文件所在的文件夹中,然后将java_home环境变量指向该jre,以便当我双击jar文件时,如果没有jre文件,它将知道jre的位置.安装在目标(Mac OS)系统上?

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?

我一直在看以下链接:

https://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html

但是,这似乎与通过Mac App Store部署应用程序有关.我只是希望用户能够无需安装JRE就可以单击并运行Java jar文件.

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.

我还查看了一些链接,说它们使用Launch4j或jPortable,但我宁愿不必依赖于第三方软件.

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.

如何在不手动安装 JRE 的情况下运行 jar?

如何我如何在Windows上编译的Ubuntu中运行JAR文件?

推荐答案

Java 14及更高版本包含一个名为此处.简而言之,这样的事情应该起作用:

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'

这篇关于如何打包Java jar文件以在未安装JRE的Mac上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆