There are 3 common reasons for this:
On windows, and using sysin/sysout
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.
jar file broken
A runnable jar file is one that has three properties:
- There is a class inside the jar that has a
public static void main(String[] args)
method inside.
- That class is named (fully qualified) in the manifest of the jar, under key
Main-Class
- Any deps needed are either baked into the jar, or in another jar, and those other jars are named, space-separated and relative to the dir that the jar you're double clicking lives in, in the manifest, under key
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.
java install broken
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
).