简体   繁体   English

如何从命令行调用嵌入式jre以运行java应用程序

[英]How to call an embedded jre from command line in order to run java applications

Is it possible to bundle a JRE within an exported stand alone Java app? 是否可以在导出的独立Java应用程序中捆绑JRE? 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 我们有一个非常具体的要求,即在没有安装最新Java版本的机器上运行独立的AnyLogic Java应用程序,并且由于公司的IT策略,我们无法这样做

Through some research I have found some sites to claim that they have already been doing it for Windows and Mac. 通过一些研究,我发现一些网站声称他们已经在为Windows和Mac做过。

Using a bundled JRE on OSX https://wiki.openjdk.java.net/display/MacOSXPort/How+to+embed+a+.jre+bundle+in+your+Mac+app http://www.intransitione.com/blog/take-java-to-app-store/ 在OSX上使用捆绑的JRE https://wiki.openjdk.java.net/display/MacOSXPort/How+to+embed+a+.jre+bundle+in+your+Mac+app http://www.intransitione.com /博客/采取-Java到应用商店/

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. 我的问题是,这些帖子中的大多数都是指为Mac OS x捆绑应用程序,并要求在像Eclipse这样的IDE中创建jar文件。 But since I use AnyLogic the jar files gets exported without myself being able to intervene. 但是因为我使用AnyLogic,所以jar文件会被导出,而我自己无法进行干预。 What I need is to change the command line code that runs the jar files and currently looks like this: 我需要的是更改运行jar文件的命令行代码,目前看起来像这样:

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) (注意:代码因可读性而降低)

into something that I assume will pass the jre or JVM to be used as an argument to the java call. 我假设将传递jre或JVM作为java调用的参数。 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. 或者可能设置用于java或其他东西的目录......因为在没有安装java的机器上调用java命令不会呈现任何内容。

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

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

Thanks 谢谢

A colleague of mine who is not on Stack Exchange gave me the answer so here goes, actually quite easy: 我的一位不在Stack Exchange上的同事给了我答案,所以这里很简单:

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. 为了满足我的具体情况,只需要在您提供给客户端的文件夹的根目录中包含一个jre,然后在执行文件中引用java可执行文件。 The solution for Windows and Mac are slightly different so here goes: Windows和Mac的解决方案略有不同,所以这里是:

On Mac 在Mac上

You can find the jre in the following folder. 您可以在以下文件夹中找到jre。 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 它是一个隐藏的文件夹,所以如果Mac没有设置为显示隐藏的文件夹,请转到查找程序使用命令shift-g并转到

/Library/Java/JavaVirtualMachines/

there should be a jdk folder and then navigate to 应该有一个jdk文件夹,然后导航到

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

On Windows 在Windows上

The location of the jre is in jre的位置在

c:\Program Files\Java\

you can see the location in the .bat file that AnyLogic creates automatically in line of code that looks like this: 您可以在.bat文件中看到AnyLogic根据以下代码自动创建的位置:

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

Once you have the jre copy this folder to the same location as the stand alone java app. 一旦你有jre将这个文件夹复制到与独立的Java应用程序相同的位置。 Then the only thing that remains is to change the referenced location in both mac command line executable and the windows.bat file 然后唯一剩下的就是更改mac命令行可执行文件和windows.bat文件中的引用位置

On Mac 在Mac上

Change from 改变

java -Xdock:name="AnyLogic Model"

to

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

On Windows 在Windows上

Change from 改变

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

to

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

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 现在,在Mac和Windows上运行Java应用程序将独立于计算机上的Java版本或是否已安装

another alternative is to compile your compiled application into an executable using Exe4J . 另一种方法是使用Exe4J将已编译的应用程序编译为可执行文件。 It is not free but another advantage is that you send your client only a single exe-file, not a bunch of files. 它不是免费的,但另一个优点是您只向客户端发送一个exe文件,而不是一堆文件。 (Disclaimer: not tried with the internal AL7-dbase yet but it works fine when accessing external data). (免责声明:尚未尝试使用内部AL7-dbase,但在访问外部数据时效果很好)。

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

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