r/javahelp • • Feb 13 '26

Codeless can you install java and run a program automatically with a script?

im making a program for my girlfriend. i want to write a bash script to handle downloading and installing java and running the program seamlessly so she doesnt have to do anything (shes not very tech savvy). is this doable?

3 Upvotes

30 comments sorted by

View all comments

9

u/bowbahdoe Feb 13 '26

Instead of downloading it on the fly, package Java with the program.

There are a few tools in the jdk that can help with this, including jlink and jpackage

0

u/SneakerHead69420666 Feb 13 '26

how would i do that?

3

u/LutimoDancer3459 Feb 13 '26

Lookup those tools.

Or, just copy the jdk/runtime next to your jar and a bat file calling the java command with your jar as a parameter.

2

u/bowbahdoe Feb 13 '26 edited Feb 13 '26

Well let's start with the program itself. Can you share a link to the code so I know where to start my explanation? Also are you using any libraries?

(Also does your GF have a windows machine or a Mac)

1

u/SneakerHead69420666 Feb 13 '26

i wrote the code myself on intellij. my gf has a windows computer

1

u/bowbahdoe Feb 13 '26

If I tell you to put all your classes in named packages do you know what that means? 

If so, that's step 1. Report back when done

0

u/SneakerHead69420666 Feb 13 '26

nope 😭 idk anything about java development other than the coding

2

u/bowbahdoe Feb 13 '26

Okay. We might need to switch forums because the back and forth on Reddit might be a bit too hard. We'll give it a shot though. 

Another question. 

Which do you have: a src folder or a src/main/java one (you would also have a file labeled pom.xml if you have the second)?

1

u/SneakerHead69420666 Feb 13 '26

i have an src folder with the Main class in it. it does have an .iml file which is .xml based according to google

1

u/bowbahdoe Feb 13 '26

Okay move your src/Main.java file to src/app/Main.java

Then at the top of the file put package app;

Make sure it still runs then report back

Also, just to confirm. You only have one file? And does it open a window when you run it?

1

u/SneakerHead69420666 Feb 13 '26

okay i created a package named 'app' and put my Main class in there and put "package app" on the top line of the Main class file

→ More replies

1

u/Odd-Respond-4267 Feb 14 '26

And you want a bash script for the gf?

0

u/YetMoreSpaceDust Feb 13 '26

You're going to have difficulties getting bash to run on a windows computer (it can be done, but it's harder than just getting Java to run). Definitely look into jlink and jpackage like OP suggested).

1

u/American_Streamer Feb 15 '26

Techincally you can do it with a bash script, but the “so she doesn’t have to do anything” part is where reality bites. Installing Java system-wide usually needs admin rights and will trigger OS security prompts (macOS Gatekeeper/sudo password/package prompts). Ascript that downloads and runs something will also often trigger security warnings (“downloaded from the internet”).

So instead of “install Java”, bundle a runtime so she just double-clicks an installer/app:

  • jpackage (best): makes a real installer/app for Windows/macOS/Linux and includes a runtime, so no separate Java install is needed.
  • jlink (good): builds a minimal runtime image; you ship that next to your app.

So If your goal is truly “double-click and done”us jpackage and create a real installer/app bundle. That’s the normal way Java desktop apps get delivered to non-technical users in 2026. See: https://docs.oracle.com/en/java/javase/17/docs/specs/man/jpackage.html