I am Cleaning and Building a project, which is creating its .jar file in its "dist" folder. However the issue is that, I'm not able to run it. I double click on it and nothing happens.
I have set up "bin" folder of JDK in "Path" option in environment variables.
Is there is anything that I am missing? I am new to all this and help is really appreciated.
Suggested Learn how to make executable file yourself , rather than depending on auto generated jar file
Here is a tutorial.
In case of default jar file , most likely you have to execute
java -jar MY_AWESOME_JAR_FILE_NAME.jar
There are 3 common reasons for this:
Windows, because apparently microsoft is not capable of fixing ancient silliness, forces upon apps that they either have a terminal in which case an ugly black box always pops up, or they don't, and can't later make one. That means that on windows only, there are 2 java executables: java.exe
and javaw.exe
, with as only difference that javaw doesn't get a box. But, it doesn't get a box - sysin and sysout do pretty much completely nothing.
By default, double clicking a jar starts it with javaw, which means if your app's only interaction is reading from System.in
and writing to System.out
or System.err
, you won't see anything.
There is no fix to this, other than to make a GUI app, or make a batch file (a windows only concept) that explicitly runs java.exe
.
This doesn't apply to linux or macs.
A runnable jar file is one that has three properties:
public static void main(String[] args)
method inside. Main-Class
Class-Path
. Note that the global environment variable CLASSPATH
does nothing when double clicking jars. You can check all this; jars are just zip files. Also, the jar
tool in your JDK can unpack them, and the manifest is just a file named META-INF/MANIFEST.MF
inside. You can open it up, have a look if it's properly configured.
Check any random runnable jar first. Maybe you installed a headless java. Note that these days (since JDK9 and up), an 'end user' wouldn't even install a java and the notion of double clicking a jar to run it is basically obsolete. To make 'desktop' java applications, you'd ship an entire JRE (treeshaken if you want) and you're responsible for an installer. There are some limited tools in the JDK (since 9) that help you out (such as jlink
).
Just edit manifest file adding main method in there. If you have any additional reference libraries simply put them into class path there. Manifest specificatin is located here: https://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.