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.
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 jpackage that's now included in the JDK (possibly together with jlink) tool to create an executable that can be run without a Java install.
3
u/averageshade Apr 01 '21
I see, thank you for the information
6
Apr 01 '21
Security consideration: this can be considered mobile code by security assessments, so if there are restrictions on the environment it can cause issues.
2
u/awidesky Apr 01 '21
Can we use the way we did before(just throw a same .jar to every os) too? Deploying os-dependent java app makes me confused that the concept of interpreter language seems no longer need.
3
u/feral_claire Software Dev Apr 02 '21
Sure you can, you can just distribute a jar and leave it up to the user to have Java on their system but that's not the preferred way.
If you are making a program for other Java developers or other more technical users who would already have, or would be okay installing Java it can work well. But it harms usability which is why it's generally preferred to have a standalone app that direct require to provide the runtime themselves.
1
u/awidesky Apr 02 '21
thanks!
only one thing more.. by " leave it up to the user to have ''Java'' on their system " do you meant jdk? or is there any jre released separately?
2
u/feral_claire Software Dev Apr 02 '21
The JDK. The separate JRE for users to install no longer exists (although I think Adopt offers something they call a JRE. As far as I'm aware it's not quite the same thing but can probably serve the same purpose).
1
1
u/pandainquilt Apr 01 '21
That is the one thing that I have been waiting for quite some time now. I had a look at it when it was still a JEP and then when it was in preview.
4
u/wildjokers Apr 01 '21
It has actually been available for a long time, a tool called "javapackager" was included in Java 8. Then in Java 9 it gained the ability to create small runtimes with jlink. It was great. However, it was removed in Java 11 because it was part of JavaFX so got removed with JavaFX. People were then like "wait a minute, that was a nice tool can we have it back?". So now
jpackagehas been available since Java 14 (I believe it was Java 14 when it became a preview feature...might be off by one version).1
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.
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.
1
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
0
6
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?
1
u/Wizeguy11 Apr 01 '21
It would be great if you made a tutorial on how to do this exactly
1
u/johnmc325 Apr 01 '21
That was my intention but have not got round to it yet. Instead, I put out a call for fellow developers to join me in making an application as a group where we would do all this. Looking to start on it next week. Maybe after that, I will look to put together a video.
1
u/Wizeguy11 Apr 01 '21
If it’s a learning experience being involved in this, any chase I can join??
1
u/johnmc325 Apr 01 '21
Absolutely, it's all about learning and hopefully finding people to work together with. I have sent you a message.
•
u/AutoModerator Apr 01 '21
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full
You ask clear questions
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.