Reputation: 710
I am trying to run a jar file that has been packaged by Maven. When I run java -jar target/java-prac-1.0-SNAPSHOT.jar
I get the following output:
no main manifest attribute, in target/java-prac-1.0-SNAPSHOT.jar
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localdomain.localhost.tutorial</groupId>
<artifactId>java-prac</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies></dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<manifest>
<mainClass>localdomain.localhost.tutorial.Main</mainClass>
</manifest>
</configuration>
</plugin>
</plugins>
</build>
</project>
My MANIFEST.MF file looks like
Manifest-Version: 1.0
Main-Class: localdomain.localhost.tutorial.Main
The interesting thing is that when I run ls target/classes
, the 'META-INF/' folder is listed. So the file seems to be in the jar file, java just can't find it for some reason.
Upvotes: 2
Views: 3479
Reputation: 1
Try adding the following nodes to the pom.xml file:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Upvotes: 0
Reputation: 413
pom.xml
file <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!--add you main class-->
<mainClass>cn.lonecloud.RefDemo</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
mvn compile package
java -jar target/java-prac-1.0-SNAPSHOT.jar
Upvotes: 3