简体   繁体   English

从jar文件制作Mac应用

[英]Making a mac app from a jar file

I'm trying to make a Mac app (specifically a GUI) in Java. 我正在尝试用Java制作Mac应用程序(特别是GUI)。 However, I'm not having much success. 但是,我没有太大的成功。 Here's what I've tried so far: 到目前为止,这是我尝试过的方法:

  1. Double-clicking the executable JAR file produced by Eclipse. 双击Eclipse生成的可执行JAR文件。 RESULT: Exception thrown because the Display that I create for my app must be created on the main thread. 结果:抛出异常,因为必须在主线程上创建我为我的应用创建的Display。

  2. Created my own app file that runs a Shell script that opens my JAR with the -XstartOnFirstThread command. 创建了我自己的应用程序文件,该文件运行一个Shell脚本,该脚本使用-XstartOnFirstThread命令打开我的JAR。 RESULT: This was able to run on my laptop, but gave an error (-10810) when I tried running it on another Mac. 结果:它可以在我的笔记本电脑上运行,但是当我尝试在另一台Mac上运行时出现错误(-10810)。

  3. Used Eclipse's Mac app bundler. 使用Eclipse的Mac应用程序捆绑包。 RESULT: Error code -10810 on my own laptop, saying that the app could not be launched. 结果:我自己的笔记本电脑上出现错误代码-10810,表示无法启动该应用程序。

Based on what I've seen online, the best way to fix this is to set my JAVA_HOME and PATH variables. 根据我在网上看到的内容,解决此问题的最佳方法是设置JAVA_HOME和PATH变量。 I'm not sure what would go in these variables, what I'd set them to, or where I'd set them. 我不确定这些变量中将使用什么,将它们设置为什么或将它们设置在何处。 My second option would be to include a JRE within my app. 我的第二个选择是在我的应用程序中包含一个JRE。 However, I'm not sure what the best way to do this and I have a few questions: 但是,我不确定执行此操作的最佳方法,我有几个问题:

  1. Why can't I use the system JRE? 为什么我不能使用系统JRE?

  2. How do I include an JRE in an app package? 如何在应用程序包中包含JRE? Do I just include the DMG I get from Oracle? 我是否只包括从Oracle获得的DMG?

  3. What app bundlers are out there that will do this for me? 哪些应用捆绑软件可以为我做到这一点? I tried to use the Eclipse app bundler, which didn't work. 我尝试使用不起作用的Eclipse应用程序捆绑器。 I also tried using Oracle's tutorial found here: http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html , but this tutorial points to an app bundler that is not available anymore. 我还尝试使用位于以下位置的Oracle教程: http : //docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html ,但是本教程指向的应用程序捆绑包不再可用。

What is the best way to resolve this issue? 解决此问题的最佳方法是什么? Any help is appreciated. 任何帮助表示赞赏。

Thanks! 谢谢!

You have to set JAVA_HOME and PATH variables by using the given links: 您必须使用给定的链接设置JAVA_HOME和PATH变量:

https://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/ https://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/

http://www.sajeconsultants.com/how-to-set-java_home-on-mac-os-x/ http://www.sajeconsultants.com/how-to-set-java_home-on-mac-os-x/

In many cases, JRE already exists because it was installed when the system was configured or when another program was installed. 在许多情况下,JRE已经存在,因为JRE是在配置系统或安装其他程序时安装的。 If the system where you are installing the server or client components does not have this environment, follow the instructions to download the JRE and verify the JRE environment On Mac. 如果要安装服务器或客户端组件的系统没有此环境,请按照说明在Mac上下载JRE并验证JRE环境。 Again try Eclipse app bundler (Download the latest version available and substitute the file name accordingly). 再次尝试使用Eclipse应用程序捆绑程序(下载可用的最新版本,并相应地替换文件名)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM