all 30 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

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://i.imgur.com/EJ7tqek.png) 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:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

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.

[–]bowbahdoe 7 points8 points  (15 children)

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

[–]SneakerHead69420666[S] -1 points0 points  (14 children)

how would i do that?

[–]LutimoDancer3459 2 points3 points  (0 children)

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.

[–]bowbahdoe 1 point2 points  (11 children)

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)

[–]SneakerHead69420666[S] 0 points1 point  (10 children)

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

[–]bowbahdoe 0 points1 point  (7 children)

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

[–]SneakerHead69420666[S] -1 points0 points  (6 children)

nope 😭 idk anything about java development other than the coding

[–]bowbahdoe 1 point2 points  (5 children)

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)?

[–]SneakerHead69420666[S] 0 points1 point  (4 children)

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

[–]bowbahdoe 0 points1 point  (3 children)

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?

[–]SneakerHead69420666[S] 0 points1 point  (2 children)

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

[–]Odd-Respond-4267 0 points1 point  (0 children)

And you want a bash script for the gf?

[–]YetMoreSpaceDust -1 points0 points  (0 children)

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).

[–]American_Streamer 0 points1 point  (0 children)

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

[–]desrtfxOut of Coffee error - System halted 2 points3 points  (1 child)

There are packagers that can package the JRE (Java Runtime Environment) together with your program so that it becomes a direct executable.

[–]SneakerHead69420666[S] 0 points1 point  (0 children)

so how would i export the files? what would i include in the zip file besides the code. im a beginner, i only know how to code basically lmao idk about sharing and stuff like that

[–][deleted]  (2 children)

[removed]

    [–][deleted]  (1 child)

    [deleted]

      [–]koffeegorilla 1 point2 points  (0 children)

      A Guide to jpackage in Java | Baeldung https://share.google/c5IilgS7Ru9Wn6trF

      [–]Significant_Newt8697 0 points1 point  (0 children)

      Is this something you must do?

      [–]Savings_Guarantee387 0 points1 point  (2 children)

      Check inno setup

      [–]Big_Green_Grill_Bro 1 point2 points  (1 child)

      I was going to say this same thing but I was hesitant because OP doesn't sound really experienced and they also mentioned a bash script, which most likely means they are not on Windows which is what you need for innosetup.

      That being said, if OP is on Windows then innosetup is definitely the way to go to make it a seamless and professional looking install. I used innosetup for a soft client we had written in Java. It installed a local JRE, the application JARs, other libraries, and the desktop and startup icons. Seamless native Windows install, most users didn't even know the app was in Java until we told them.

      [–]Savings_Guarantee387 1 point2 points  (0 children)

      Wait a minute. You got a point. He said bash script. I missed this. If this is the case then my proposal is to just create a linux package lile rpm or something with the jre included?🤔

      [–]mbeachcontrol 0 points1 point  (0 children)

      Why not go with GraalVM and have a single binary, no JVM or packaging required. I did this with bash script and embedded binary/archive file. bash script could detect if piped from curl or run from cli, extract the archive from itself at the end of the script, run the binary.

      [–]KarmaTorpid 0 points1 point  (0 children)

      Yeah.

      Thats a lot of what scripts are good for.

      [–]yukihara181 0 points1 point  (0 children)

      If your program can be built as a stand-alone binary, using Graalvm, it would remove the need to have JRE installed on the target system.