如何在不安装JDK/JRE的情况下运行Java应用程序?

huangapple go评论67阅读模式
英文:

How to run a Java application without installing JDK/JRE?

问题

我使用Java和Selenium开发了一个独立的应用程序。当我创建一个可执行的JAR文件并在我的计算机上运行它时,它能够正常工作。但是这个可执行的JAR文件在另一台计算机上却无法运行。双击时没有任何反应。我希望在不在那台计算机上安装JDK/JRE的情况下运行我的应用程序。我正在使用Eclipse,并且在Windows 10操作系统上工作。有什么解决方案吗?

英文:

I have developed a standalone application using Java and Selenium. When I create an executable jar and run it on my machine, it is working fine, but that executable jar is not working on another machine. On double click, nothing is happening. I want to run my application without installing installing JDK/JRE on that machine. I am using Eclipse and working on Windows 10 machine. Any solution?

答案1

得分: 1

它在你的机器上运行是因为你已经安装了JDK/JRE。

在目标机器上没有安装JDK/JRE的情况下无法运行它们。这就是操作系统独立性的原因。也就是说,只要它们安装了JDK/JRE,你可以在Windows、MacOS和Linux上运行相同的代码/应用程序。

英文:

It runs on your machine because you already do have JDK/JRE.

It is not possible to run them without JDK/JRE installed on the target machine. This is the reason for the OS independency. ie. you can run the SAME code/app on Windows MacOS Linux (given that they have JDK/JRE installed).

答案2

得分: 0

你需要使用Gradle或者Maven来部署使用Java(Java 11+)的独立应用程序,我实际上正在使用Gradle。

在build.gradle文件中添加org.beryx.runtime插件:

plugins {
    id 'java'
    id 'application'
    id 'org.beryx.runtime' version '1.9.1'
}

runtime {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages'] 
    jpackage {
        imageOptions = ['--icon', file('/icon/icon.ico')]
        imageName = '你的可执行文件名'
        skipInstaller = true
    }
}

这将生成一个包含JDK/JRE运行时的可执行文件。对于我的项目,我正在使用JDK 14.0.1和Gradle 6.4。

访问 Beryx Badass 的 GitHub 页面 以获取更详细的信息。

英文:

u need use gradle or maven to deploy standAlone app with java (java 11+) ,, i am actually using gradle.

on build.gradle :
add org.beryx.runtime on plugin ->

plugins {
id 'java'
id 'application'
id 'org.beryx.runtime' version '1.9.1'
}

runtime {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages'] 
jpackage {
    imageOptions = ["--icon", file("/icon/icon.ico")]
    imageName = "ur exe name"
    skipInstaller = true
}
}

this is will produce exe file with jdk/jre runtime inside,,
for my project iam using jdk14.0.1 , gradle-6.4.

go to Beryx Badass github for more deep info about this

答案3

得分: 0

有一些可以运行基本代码的在线编译器。
https://www.tutorialspoint.com/compile_java_online.php

在编写涉及导入库、保存和加载文件等更复杂系统时,最好在本地使用JDK/JRE。

英文:

There are online compilers that can run basic code.
https://www.tutorialspoint.com/compile_java_online.php

It is best to use JDK/JRE locally when coding more complex systems that import libraries and save and load files, etc.

huangapple
  • 本文由 发表于 2020年7月24日 08:52:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63065229.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定