Issue
I've build this project with mvn clean install
. Now I have a .jar
file but I'm not able to use it with:
λ java -jar flyway-commandline-xxx.jar
no main manifest attribute, in flyway-commandline-xxx.jar
What am I missing?
Solution
An executable jar needs a "manifest file" - which is located at META-INF/MANIFEST.MF
inside the jar.
You can use the Maven Assembly plugin to produce this manifest file in line with this:
...
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<archive>
<manifest>
<mainClass>dk.tbsalling.ais.cli.AisCli</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
...
The MainClass
(referenced in the manifest file) is the class containing the main(...)
-method called when you execute the jar.
You can have a look at https://github.com/tbsalling/aiscli/blob/master/pom.xml for a full, working example.
Answered By - tbsalling
Answer Checked By - Gilberto Lyons (JavaFixing Admin)