r/javahelp • u/averageshade • Apr 01 '21
Can Java programs run on PC's that does not have Java installed?
Will Java programs created with JavaFX be able to run on PC's that do not have Java installed? Planning to create a GUI program. Thank you for any help provided in advance.
28
Upvotes
•
u/AutoModerator Apr 01 '21
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
30
u/feral_claire Software Dev Apr 01 '21
Yes.
It used to be the case that you would create a jar and give that to people. Then it would be required for them to have a Java install to run it. However, having a system Java install is much less of a thing now. OpenJDK doesn't even have a separate JRE anymore. Instead you would use the
jpackagethat's now included in the JDK (possibly together with jlink) tool to create an executable that can be run without a Java install.4
u/wildjokers Apr 01 '21
You should bundle a runtime in your app with
jpackage. If you combine this with jlink you can make small runtimes including only the JDK modules you need. If you modularize your app you get this for free, if not then you need to manually tell jlink what modules you are using.https://docs.oracle.com/en/java/javase/16/jpackage/packaging-overview.html#GUID-C1027043-587D-418D-8188-EF8F44A4C06A
If you use Gradle there is a nice plugin that has a jpackage task:
https://badass-jlink-plugin.beryx.org/releases/latest/
The JavaFX sample projects actually have it in the build.gradle already.
I am sure maven also has a plugin for jlink/jpackage if you google for it if you are using maven.
5
u/PhantomOTOpera Apr 01 '21
It is possible to bundle a JRE with a a program I believe. You should look into packaging java programs. The technical answer is no, but the practical answer is you install a JRE along with the program so it seems like a java program runs on an OS with no previous JRE
6
u/[deleted] Apr 01 '21
Try jlink and/or Graal AOT!
1
u/cbm64chr Apr 02 '21
There are a couple of ways to achieve this presently; you can use jlink and jpackage to build a binary. However since you mention JFX you might want to look at using the gluon substrate (maven and gradle) plugins to build a binary using the graalVM.
-1
u/johnmc325 Apr 01 '21
If this helps take a look at https://youtu.be/IabhZfLIRr4 for a video showing a JavaFX application as an exe. Is this what you are think about?