导出带有VM参数的jar [英] Exporting jar with VM arguments

查看:205
本文介绍了导出带有VM参数的jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Eclipse编写了一个Java应用程序,该应用程序将SWT用于UI. (请参阅).

I've written a Java application with Eclipse that uses SWT for the UI. (see SWT Exception when running jar: Exception in thread "main" org.eclipse.swt.SWTException: Invalid thread access for detail).

我导出为JAR,但无法从Finder和Terminal运行它.我终于用java -XstartOnFirstThread -jar CommonDenom.jar

I exported as JAR and was having trouble getting it to run from Finder as well as from Terminal. I finally got it to run from Terminal with java -XstartOnFirstThread -jar CommonDenom.jar

但是,当我从eclipse导出为JAR时,我仍然无法运行它.这是因为它在导出时需要与参数-XstartOnFirstThread捆绑在一起.然后我注意到在Properties >> Run/Debug Settings >> commonDenom >> Edit >> (x)= Arguments中有一个复选框,上面写着在使用SWT启动时使用-XstartOnFirstThread自变量".但是已经检查过了.因此,我认为此选项仅在使用Eclipse启动代码时适用,而不适用于导出的JAR.

I still, however, cannot get it to run when I export as a JAR from eclipse. This is because it needs the argument -XstartOnFirstThread bundled with it when it exports. Then I noticed that in Properties >> Run/Debug Settings >> commonDenom >> Edit >> (x)= Arguments there is a tick-box that says "Use the -XstartOnFirstThread argument when launching with SWT." But it was already checked. So I figured this option only applies when launching the code with Eclipse, and doesn't apply to the exported JAR.

因此,我将参数手动添加到同一选项卡的VM Arguments框中.当我导出为可运行的JAR时,我注意到一条警告,上面写着:"VM参数将不属于可运行的JAR.启动JAR时可以在命令行中传递参数.

So I added the argument manually to the VM Arguments box in the same tab. When I went to export as a runnable JAR, I noticed a warning that reads "VM arguments will not be part of the runnable JAR. Arguments can be passed on the command line when launching the JAR.

最终,我需要一种方法来使它从finder(无论是JAR还是其他)中启动,而无需打开Terminal并手动启动它.是的,我可以编写一个Shell脚本来启动它,但是我觉得必须有一种更简单的方法.

Ultimately, I need a way to get this to launch from finder (be it JAR or otherwise) without having to open Terminal and launch it manually. Yes, I can write a Shell script to launch it, but I feel there must be a simpler way.

推荐答案

您有两个选择.简单的方法是创建一个shell脚本:

You have two options. The easy way is to create a shell script:

#!/bin/bash
java -XstartOnFirstThread -jar CommonDenom.jar

用户运行脚本,该脚本设置参数并运行Java.

The user runs the script, which sets the arguments and runs Java.

另一种方法是创建一个 appbundler工具创建应用程序捆绑包.

The other way is to create an Application Bundle. It include a properties file (Info.plist) where you can set these properties. You can also use Oracle's appbundler tool to create an application bundle.

这篇关于导出带有VM参数的jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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