After building a sample mvn project, I added my org.restlet
dependencies & Java code.
Then, I successfully built my JAR via mvn install
. Finally, I ran into an error when trying to run the JAR.
vagrant$ java -jar target/my-app-1.0-SNAPSHOT.jar
Failed to load Main-Class manifest attribute from
target/my-app-1.0-SNAPSHOT.jar
The manifest file is named MANIFEST. MF and is located under the META-INF directory in the JAR. It's simply a list of key and value pairs, called headers or attributes, grouped into sections.
You need to set the main class in the manifest using the maven-jar-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.someclass.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Taken from here.
EDIT
If you want to package the resulting jar with dependencies you can use this
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.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>
Taken from here.
If you dont have a manifest in your jar invoking java -jar will not work.
Use this command if you dont have a manifest:
java -cp foo.jar full.package.name.ClassName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With