DEV Community

Calin Baenen
Calin Baenen

Posted on

How can I make my Jar file executable on all computers?

I want my application to be usable on all computers, but it only works on mine.
Apparently this has something to do with it checking for versions of Java relative to the computer(???).

I'm either a fucking noob at Java, and has no life to not be using any good tools (a.k.a. primitive, ancient, and lesser-skilled), or there aren't that many tools for it (either way, I should understand why it's not working, if I wanna work in Java).
What I want to do is convert my .jae which works on only my computer to a .jar (yes, another .jar, so that it's still platform-independent) that will work on ALL computers that have a JRE (native or manually installed).

Of course I'm too naive to understand any of this (since I'm so homosapien-like, I use CMDPrompt to compile and view errors (that VSCode didn't warn me of)), so, do any of you know of any tools I could use to accomplish my overall goal?

Thanks in advance! It means a lot to me.
Cheers!

Top comments (12)

Collapse
 
desirtechnologies profile image
Jeffrey Desir

✌🏿 Yo Calin, it's been years since I've considered myself a Java programmer, but I can help if you're just trying to create an uberjar... consider using a build tool like Maven. Assuming you're using Maven (Apache Project Manager)

  1. maven MainProgram.java --uber-jar or maven *.java --uber-jar (wildcard *).

  2. java MainProgram.jar


Why is a build tool recommended?
Why not just javac? Depends on what kind of executable you want, dependency complexity, etc.
Here's a nice diagram I'm commiting to memory by a kind Mr. Falkner
.

In short, if you want to guarantee your java executable has ALL it needs to run platform-agnostic, compile it's dependencies, runtime, and project code all together with zie uber-jar!.

Collapse
 
desirtechnologies profile image
Jeffrey Desir

P.S.
Visual Studio has a Java extension.
I'm curious to your build process; I've haven't generated anything but .class & .jar file types with a java build. I know JAE is Java Application Environment; I wonder is that some minified JRE for your artifacts or is my Java really that weak? (no regrets, Clojure liberated me from OOP).

Collapse
 
calinzbaenen profile image
Calin Baenen

You are curious? I'd love to explain. Though, I don't fully understand the question. or what you mean by "build process" specifically, since I (kind of) explained in my post.
All I do is write some .java, write a manifest, write compiler.bat, and compile my Java in to a Jar.

Collapse
 
calinzbaenen profile image
Calin Baenen

I'm not sure I fully understand what's going on. As I said, I'm primitive. It's like your showing bacteria fire, and getting it to understand.
I don't mean to burden to ask, but can you simplify it, and maybe link some explanations/documentation?

Thanks for your help so far.
Cheers.

Collapse
 
jmfayard profile image
Jean-Michel 🕵🏻‍♂️ Fayard

That's not so simple actually
Big applications like Android Studio or IntelliJ just includes their own copy of the JRE inside the app.

I googled a bit for you and found this docs.oracle.com/javafx/2/deploymen...

and also this

GitHub logo fvarrui / JavaPackager

📦 Gradle/Maven plugin to package Java applications as native Windows, Mac OS X, or GNU/Linux executables and create installers for them.

JavaPackager

Maven Central

JavaPackager is a hybrid plugin for Maven and Gradle which provides an easy way to package Java applications in native Windows, Mac OS X or GNU/Linux executables, and generate installers for them.

SNAPSHOT version is not released to Maven Central, so you have to install it manually.

👀 See JavaPackager changes and fixes.

History

It was born while teaching to my students how to build and distribute their Java apps, and after seeing that a chain of several plugins was needed to achieve this task, I decided to develop a plugin 💍 to govern them all.

How to use this plugin

Package your app with Maven

Add the following plugin tag to your pom.xml:

<plugin&gt
    <groupId>io.github.fvarrui</groupId&gt
    <artifactId>javapackager</artifactId&gt
    <version>1.4.2</version&gt
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
calinzbaenen profile image
Calin Baenen

I know how to do the second to last one, but how do I do the second one?
Section 5.5 of the linked Oracle documentation.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

The solution is platform-specific. I believe you can find on SO.

But in essence, bundle JRE with the app.

Collapse
 
calinzbaenen profile image
Calin Baenen

How do I "bundle a JRE with it"? Also, what does "SO" in this case (StackOverflow)?

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

My process was to use Gradle to create shadow JAR. Maven also has a different plugin to create a fat JAR, I believe.

About bundling a JAR file, would you rather want users to install JRE? If not, which OS do you want to try first (which one are you running)?

Thread Thread
 
calinzbaenen profile image
Calin Baenen

In regards to the second to last question, it'd be fine, as long as the user can run the Jar, but I'm not familiar with any tools, so I want to know if there are any simple tools (for dumbasses like me). :p
Though, if it helps find anything, I'm using Windows 10.

Thread Thread
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

If you use no build tools, just pure javacand java -jar, it should already be fat JAR by default, I believe.

Thread Thread
 
calinzbaenen profile image
Calin Baenen

Well, it doesn't work on other computers, so, are there any settings I need to apply?