trying to make executable .jar file
I coded a program in intellij with using maven, made an artifact and build it, and if I run the .jar file which gets created using cmd it works.
Now I want to make it executable with a double-click without the need of an additional file, but when I try to run it that way an error message saying "A java Exception has occured." pops up, even tho it works when starting the file using
java -jar file.jar
in cmd.
I also installed jarfix prior to this and run it as admin, it works for other .jar files which I needed it for, but doesn't help with my own program.
What am I doing wrong?
88 Replies
β
This post has been reserved for your question.
Hey @Lloyd_159! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
π€
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
Are you sure it packaged the correct JRE into your jar? This error often occurrs when you want to start some newer JARs with Java 1.8.0.
how can I check which JRE I am using in my build?
okay my I think I found it, In my project structure it says I'm using SDK 19. Tho when I run
java -version
in cmd, it says my current installed java version is 20.0.2, so I should be fine?I thought you were making a stand-alone jar so your installed Java should not matter in that case.
oh okay lol
so sry for my confusion, but which JRE do I have to use and how can I check that I have the right one?
(I thought you meant just using the JRE which I have installed or smth like that)
Can you show how you create the jar?
I think jarfix should allow configuring the Java version/JDK installation you are using?
I include my main class in my pom.xml in maven:
then I going to File -> project strucutre -> artifacts -> add -> JAR -> from modules with dependencies
in that menu I choose a namen and the same main class as the one from the pom.xml file and select "extract to the target JAR", click ok and then apply
afterwards I go to Build -> Build Artifacts -> select the artifact I just created and click Build
the file appears in my
out
folder
when I run it using cmd as descripted in the original message it works and the gui pops up, but with a double click the error appears
no clue how to do that, jarfix it never gave me that optionDouble click might not use the
-jar
in the command.do you know how I can fix that?
that's what jarfix takes care of
Can you show the output of jarfix?
wait wdym?
like when I execute jarfix?
What does jarfix show when you run it?
yeah
uh it's in German
it's fine

ok yeah that's a JDK 8 JRE
try running
jarfix /k
and are you logged in as an administrator?does it matter where I do it?
yes
?
like in which directory
because cmd doesn't know the command "jarfix"
you need to use the right location for jarfix
either run it in the directory you installed jarfix in
okay
or use something like
C:\path\to\jarfix.exe /k
well it executed but nothing happened
wait nvm
jarfix was executed and asked me for permission
but nothing else
no output?
not even where you ran it?
I just opened cmd and ran
C:\Users\username\Downloads\jarfix.exe /k
no output thoalso no output inside cmd?
nope
nothing
I assume the JAR still doesn't work?
it doesn't
What's the output of
C:\Users\username\Downloads\jarfix.exe
without /k
?also no output
and jarfix also asks me to allow changes to my pc
and nothing if you allow it?
no, nothing
no gui which opens or output, and also no output in cmd
adding
/u
doesn't change anything either?no change
Can you try running jarfix from an administrator cmd?
i.e. use the "run as administrator" option with cmd
okay
no change except jarfix doesn't ask me to allow changes
and double-clicking jarfix shows the output?
wait no it doesn't now
imma restart my device ig?
Then how did you get to that?
it appeared when running jarfix via double click, but no it doesn't
maybe it's still open?
back
I don't think it was but now I'm not too sure lol
anyways I'll run the command again
okay now it has a different window

that's good
should I try to run my .jar again?
yes
Now it configured to use JDK 20
oh yes it works
nice, thanks xD
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
so whenever I need to update jarfix I can just run it with /k?
/k
just means it tries to detect a JDK
so it skips JREsokay got it, thx
it's also possible to specify a specific JDK
like by just adding the exact jdk instead of /k?
no you'd need to run it with
/x
which generates an ini file to configure it - if you edit that file, you can change which JDK jarfix usesJarfix
Jarfix fixes the jar file association on Windows
okay I'll definitely safe this xD
alternatively you can just select to associate the .jar extension when installing a JDK
At least with Adoptium/Temurin (the JDK I'd usually use), that works well
okay thanks
again, thank you very much for your help <3
If you install the JDK from Oracle, idk whether that option is present
I don't think so, but they seem to have their own download page
yea that's where I've been rn :P
I'd install Java from there because
- It works well/doesn't cause issues
- It's TCK certified (OracleJDK and most other major JDKs are as well) and production-ready
- It's actually an Open Source version and you can use it commercially forever without paying for it
- You have the option to enable/disable these things
- some other things maybe
I've been using Amazon Corretto bc it's the intellij preset, but if you recommend this one I'll definitely change I think lol
at least before creating the next project
Coretto is fine as well
But yeah if you install the JDK from inside IntelliJ, it won't ask you to associate the .jar extension
I guess I'll still have a look when I create my next project, bc I know nothing abt the jdk I use actually πΆβπ«οΈ
The JDK is the Java installation you are using to develop your application
newer JDK means you can use more Java features
yes I know that, i meant I don't know nothing about the difference between the distributions like corretto, adoptium, opendjk etc
it's also possible to use a new JDK to write applications for older Java versions (if an application is written for some Java version, it can normally be used with all newer Java versions) but then you cannot use the new features of the new version
these are just different vendors/organizations
okay gotcha
or flavours in some cases (there are cases where some vendor has multiple flavours with some difference)
but the java features they provide are the same, right?
like the code of openJDK 21 ir the same as adoptium 21 for example
yes
oh okay this is useful
though there isn't really a single "OpenJDK"
using that name to refer to a specific JDK isn't really correct
like there are different organisations which call their jdk like that?
both Adoptium/Temurin are openjdk/jdk distributions just like Coretto
oh okay that makes sense
I just change my registry entries directly.
- OpenJDK is https://openjdk.org and https://github.com/openjdk - you can't download a JDK from there (only build it yourself)
- Oracle is the company doing most of the work behind Java and provides OracleJDK (commercial) - they also make GraalVM
- The Eclipse Foundation (a not for profit organization with many member companies) provides Temurin (Adoptium is their project name)
- Amazon makes Corretto
- Azul makes Zulu and Azul Prime
- ...
I just don't use Windows lol
and even on Windows, the Temurin msi installer sets it up properly
oooh okay, that made things more clear now
the main difference is commercial support and licensing
there are also some performance differences and some non-language (e.g. tooling, GC, etc) features in some cases
yea okay
Post Closed
This post has been closed by <@765577368030937129>.