简体   繁体   English

带jar的便携式JVM

[英]Portable JVM with jar

Is it possible to pack a JVM or JRE with a jar file so that assuming the user does or doesn't have Java installed, it will always resort to the packed JVM. 是否可以用jar文件打包JVM或JRE,以便假设用户已安装或未安装Java,它将始终使用打包的JVM。 My guess is that it would require some sort of c/c++ program which would take away the multi platform aspect of java. 我的猜测是,这将需要某种c / c ++程序,而这会剥夺Java的多平台方面。 This is fine, as long as the platform is Windows. 只要平台是Windows,就可以了。 Also it would be best if the user doesn't get a prompt to install the JVM, the program just launches it and then the application with no prompt for the user to install anything. 同样最好的是,如果用户没有提示安装JVM,程序只是启动它,然后应用程序又没有提示用户安装任何东西。

To add up to @home answer on packing a JRE: 要在打包JRE时总计@home答案:

  1. zip the jre directory of your OS (eg for Windows: C:\\Program Files\\Java\\jre7 ) 压缩操作系统的jre目录(例如,对于Windows: C:\\Program Files\\Java\\jre7
  2. unpack it somewhere on the destination computer (eg D:\\MyProgram\\jre7 ) 将其解压缩到目标计算机上的某个位置(例如D:\\MyProgram\\jre7
  3. possibly modify the PATH environment variable (eg set PATH=%PATH%;D:\\MyProgram\\jre7\\bin ) 可能会修改PATH环境变量(例如, set PATH=%PATH%;D:\\MyProgram\\jre7\\bin

If you're not allowed to modify PATH , you can just explicitly specify D:\\MyProgram\\jre7\\bin\\java.exe -jar MyProgram.jar in a startup script. 如果不允许您修改PATH ,则只需在启动脚本中显式指定D:\\MyProgram\\jre7\\bin\\java.exe -jar MyProgram.jar

This is fine, as long as the platform is Windows. 只要平台是Windows,就可以了。

If all you want to support is Windows, what is the attraction of Java (as opposed to, for example, .Net)? 如果您只想支持Windows,那么Java(与.Net相对)的吸引力是什么?

Also it would be best if the user doesn't get a prompt to install the JVM, .. 如果用户没有提示安装JVM的话,那也是最好的。

Not according to this user. 并非根据此用户。 Ever heard of UAC? 听说过UAC吗? If my fully enabled UAC failed to catch that and prompt me, I'd be raising a bug report with MS. 如果我完全启用的UAC无法捕获并提示我,我将向MS提出错误报告。


Oracle provides the deployJava.js to ensure that a suitable minimum version of the JRE is installed before running an applet or providing a launch button for apps. Oracle提供了deployJava.js,以确保在运行小程序或为应用程序提供启动按钮之前,已安装合适的最低JRE版本。 You might adapt the 2nd function to link directly to the executable Jar. 您可以修改第二个函数以直接链接到可执行的Jar。

I am ware of 2 different approaches: 我知道2种不同的方法:

  1. Use a (commercial) installer, eg InstallShild 使用(商业)安装程序,例如InstallShild
  2. Create an (executable) ZIP containing your JARs and a JRE. 创建一个包含您的JAR和JRE的(可执行)ZIP。 You can define a command to be executed after the user unpacked the ZIP file. 您可以定义在用户解压缩ZIP文件之后要执行的命令。 There is no need to install the JRE in the OS, your startup script (.bat, etc.) must directly point to the JRE you delivered. 无需在操作系统中安装JRE,您的启动脚本(.bat等)必须直接指向您提供的JRE。 Inside the JRE directory you can find a file describing how you can bundle your JRE with an application. 在JRE目录中,您可以找到描述如何将JRE与应用程序捆绑在一起的文件。 BTW: You may end up with different deployment units per environment (eg 32-bit, 64-bit) 顺便说一句:您可能最终在每个环境中使用不同的部署单元(例如32位,64位)

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

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