I have installed an application, when I try to run it (it's an executable jar) nothing happens. When I run it from the commandline with:
java -jar "app.jar"
I get the following message:
no main manifest attribute, in "app.jar"
Normally, if I had created the program myself, I would have added a main class attribute to the manifest file. But in this case, since the file is from an application, i cannot do that. I also tried extracting the jar to see if I could find the main class, but there are to many classes and none of them has the word "main" in it's name. There must be a way to fix this because the program runs fine on other systems.
Best Solution
First, it's kind of weird, to see you run
java -jar "app"
and notjava -jar app.jar
Second, to make a jar executable... you need to jar a file called META-INF/MANIFEST.MF
the file itself should have (at least) this one liner:
Where
com.mypackage.MyClass
is the class holding the public static void main(String[] args) entry point.Note that there are several ways to get this done either with the CLI, Maven, Ant or Gradle:
For CLI, the following command will do: (tks @dvvrt)
For Maven, something like the following snippet should do the trick. Note that this is only the plugin definition, not the full pom.xml:
Latest doc on this plugin: see https://maven.apache.org/plugins/maven-jar-plugin/
(Pick a
<version>
appropriate to your project.)For Ant, the snippet below should help:
Credits Michael Niemand -
For Gradle: