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?
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.
Use below 2 maven plugins in pom.xml:
Since, in assembly plugin below, appendAssemblyId is false, so final jar name will be with appname.jar only. You can test assembly using command: "mvn clean compile assembly:single". (or using Jenkins JPaC file then add the command "clean compile assembly:single" under mavenGoals).
See below:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>appname</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.myorg.appname.MainClass</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.myorg.appname.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
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.