Portable JVM with jar

2019-08-04 07:25发布

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. My guess is that it would require some sort of c/c++ program which would take away the multi platform aspect of java. This is fine, as long as the platform is 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.

3条回答
看我几分像从前
2楼-- · 2019-08-04 07:38

To add up to @home answer on packing a JRE:

  1. zip the jre directory of your OS (e.g. for Windows: C:\Program Files\Java\jre7)
  2. unpack it somewhere on the destination computer (e.g. D:\MyProgram\jre7)
  3. possibly modify the PATH environment variable (e.g. 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.

查看更多
我命由我不由天
3楼-- · 2019-08-04 07:45

This is fine, as long as the platform is Windows.

If all you want to support is Windows, what is the attraction of Java (as opposed to, for example, .Net)?

Also it would be best if the user doesn't get a prompt to install the JVM, ..

Not according to this user. Ever heard of UAC? If my fully enabled UAC failed to catch that and prompt me, I'd be raising a bug report with 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. You might adapt the 2nd function to link directly to the executable Jar.

查看更多
做自己的国王
4楼-- · 2019-08-04 07:54

I am ware of 2 different approaches:

  1. Use a (commercial) installer, e.g. InstallShild
  2. Create an (executable) ZIP containing your JARs and a JRE. You can define a command to be executed after the user unpacked the ZIP file. There is no need to install the JRE in the OS, your startup script (.bat, etc.) must directly point to the JRE you delivered. Inside the JRE directory you can find a file describing how you can bundle your JRE with an application. BTW: You may end up with different deployment units per environment (e.g. 32-bit, 64-bit)
查看更多
登录 后发表回答