Java 将 .jar 转换为 OSX 可执行文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2695214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert .jar to an OSX executable?
提问by Danny King
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.
我制作了一个 Java 应用程序,我想在不分发 jar 文件的情况下在 Windows、OSX 和 Linux 上分发它。我使用了很棒的 Windows exe 包装器http://launch4j.sourceforge.net/来创建一个 .exe 文件,并带有我的图标,不会吓到 Windows 用户。
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).
是否有类似的包装器可以用于 OSX/Unix?一个重要的考虑是我希望在可执行文件上有我自己的图标(特别是对于 mac 用户)。
Thanks!
谢谢!
采纳答案by Michael Aaron Safyan
Yes, on Mac OS X there is a program called Jar Bundlerthat is installed when you install the free (assuming that you already own a copy of Mac OS X) Xcode Developer Toolsthat 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.
是的,在 Mac OS X 上有一个名为Jar Bundler的程序,当您安装免费的(假设您已经拥有 Mac OS X 的副本)Xcode Developer Tools时会安装该程序,它允许您将 JAR 文件捆绑在本机 Mac OS 中X "*.app" 应用程序包与其他应用程序一样,带有漂亮闪亮的图标。
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-macappbundleplugin for Gradle will create such a wrapper app.
更新
更高版本的 OS X 上不存在 JAR 捆绑程序。作为一种解决方法,您可以手动创建一个调用 Java 的 OS X 项目。或者,有多种构建系统扩展可以做类似的事情;例如,Gradle的gradle-macappbundle插件将创建这样一个包装器应用程序。
回答by Thilo
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.
如果您没有 Mac 来构建它(或想将其集成到现有的构建链中),您可能需要查看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.
这将(如果在 Linux 或 Windows 上运行)创建一个 zip,它将解压缩为适当的 Mac 应用程序。如果你在 Mac 上运行 Maven,它也可以制作一个 DMG。
回答by Emmanuel Bourg
You can also package your application with the JarBundler Ant task:
您还可以使用 JarBundler Ant 任务打包您的应用程序:
http://informagen.com/JarBundler
http://informagen.com/JarBundler
<jarbundler dir="release"
name="MyApp"
mainclass="org.foo.myapp.Main"
jar="myapp.jar" />
回答by Marco
JarBundler is obsolete, but there is a (better) official replacement: the javapackagertool.
JarBundler 已过时,但有一个(更好的)官方替代品:javapackager工具。
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.
对于 OSX,关于如何从 Java 创建 DMG 的简单、解释清楚的分步教程在这里:http: //centerkey.com/mac/java/。对于其他平台,您只需要使用 javapackager 中的适当开关来修改示例。
回答by Xenon
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.
Github 用户 Jorl17 制作了一个名为 jar2app 的优秀 Python 脚本,它使用一个简单的命令即可完成此操作。它甚至可以让您自定义应用程序图标。
https://github.com/Jorl17/jar2app
https://github.com/Jorl17/jar2app
Just install it, follow the instructions, and you get the .app file.
只需安装它,按照说明进行操作,即可获得 .app 文件。