如何从命令行调用嵌入式 jre 以运行 Java 应用程序 [英] How to call an embedded jre from command line in order to run java applications

查看:27
本文介绍了如何从命令行调用嵌入式 jre 以运行 Java 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在导出的独立 Java 应用程序中捆绑 JRE?我们有一个非常具体的要求,即在没有安装最新 Java 版本的机器上运行独立的 AnyLogic Java 应用程序,但由于公司的 IT 政策,我们将无法这样做

Is it possible to bundle a JRE within an exported stand alone Java app? We have a very specific requirement to run a standalone AnyLogic Java app on a machine that does not have the latest Java version installed and due to company IT policies we will not be able to do so

通过一些研究,我发现一些网站声称他们已经在 Windows 和 Mac 上这样做了.

Through some research I have found some sites to claim that they have already been doing it for Windows and Mac.

在 OSX 上使用捆绑的 JREhttps://wiki.openjdk.java.net/display/MacOSXPort/How+to+embed+a+.jre+bundle+in+your+Mac+apphttp://www.intransitione.com/blog/take-java-to-app-store/

我的问题是,这些帖子中的大多数都涉及为 Mac OS x 捆绑应用程序,并要求在 Eclipse 等 IDE 中创建 jar 文件.但是由于我使用 AnyLogic,jar 文件被导出而我自己无法干预.我需要的是更改运行 jar 文件的命令行代码,当前如下所示:

My issue is that most of these posts refer to bundling an app for Mac OS x and requires that the jar files be created in an IDE like Eclipse. But since I use AnyLogic the jar files gets exported without myself being able to intervene. What I need is to change the command line code that runs the jar files and currently looks like this:

java -Xdock:name="AnyLogic Model" -Dnativewindow.awt.nohidpi=true -cp com.anylogic.engine.jar:com.anylogic.engine.nl.jar:lib/database/querydsl/querydsl-sql-codegen-3.6.3.jar -Xmx256m model6.Simulation $*

(注意:为了可读性减少了代码)

(Note: Code reduced for readability)

我假设将传递 jre 或 JVM 以用作 java 调用的参数.或者可能将目录设置为用于 java 或其他东西......因为在没有安装 java 的机器上调用 java 命令不会呈现任何内容.

into something that I assume will pass the jre or JVM to be used as an argument to the java call. Or maybe set the directory to be used for java or something... as calling the java command on a machine without java installed renders nothing.

我有一个非常简单的应用程序,以及我从 moneydance 应用程序获得的 jdk 插件,这是一个在 OSx 上运行的 Java 应用程序,带有自己的嵌入式 jre,可在此处获得

I have a very simple app, as well as a jdk plugin that I got from the moneydance app, which is a java app that runs on OSx with its own embedded jre, available here

https://www.dropbox.com/sh/1bedimsb0lj403t/ABDoFDYR7i?dl=0

谢谢

推荐答案

我的一个不在 Stack Exchange 上的同事给了我答案,所以在这里,其实很简单:

A colleague of mine who is not on Stack Exchange gave me the answer so here goes, actually quite easy:

为了满足我的特定情况,只需要在您提供给客户端的文件夹的根目录中包含一个 jre,然后在执行文件中引用 java 可执行文件.Windows 和 Mac 的解决方案略有不同,所以这里是:

In order to meet my specific circumstances one just needs to include a jre inside the root of the folder that you supply to a client and then reference the the java executable in the execution file. The solution for Windows and Mac are slightly different so here goes:

在 Mac 上

您可以在以下文件夹中找到 jre.这是一个隐藏文件夹,因此如果您的 Mac 未设置为显示隐藏文件夹,请转到查找程序,使用 command-shift-g 并转到

You can find the jre in the following folder. It is a hidden folder so if you Mac is not set to show hidded folders go to finder use command-shift-g and go to

/Library/Java/JavaVirtualMachines/

应该有一个jdk文件夹然后导航到

there should be a jdk folder and then navigate to

jdk1.8.0_45.jdk/Contents/Home/jre 

在 Windows 上

jre的位置在

c:\Program Files\Java\

您可以在如下所示的代码行中看到 AnyLogic 自动创建的 .bat 文件中的位置:

you can see the location in the .bat file that AnyLogic creates automatically in line of code that looks like this:

@SET PATH_XJAL="%DISK_XJAL%\Program Files\Java\jre6\bin\java.exe"

拥有 jre 后,将此文件夹复制到与独立 Java 应用程序相同的位置.然后唯一剩下的就是更改 mac 命令行可执行文件和 windows.bat 文件中的引用位置

Once you have the jre copy this folder to the same location as the stand alone java app. Then the only thing that remains is to change the referenced location in both mac command line executable and the windows.bat file

在 Mac 上

更改自

java -Xdock:name="AnyLogic Model"

./jre/bin/java -Xdock:name="AnyLogic Model"

在 Windows 上

更改自

    @SET PATH_XJAL="%DISK_XJAL%\Program Files\Java\jre6\bin\java.exe"

   @SET PATH_XJAL= \jre6\bin\java.exe"

在 Mac 和 Windows 上运行 Java 应用程序现在将独立于机器上的 Java 版本或是否安装

Running the java app on both Mac and Windows will now be independent from the Java version on the machine or whether it is installed or not

这篇关于如何从命令行调用嵌入式 jre 以运行 Java 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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