Reputation: 1407
I’ve created simple java program (maven with pom ) which when I run some command with CMD it should created a file under given path... I do mvn clean install
which finish successfully,
Now I want to use this created jar from the command line like follwoing:
java -jar "/Users/i012/IdeaProjects/myproj/target/test.rts-1.0-SNAPSHOT.jar" path2genfile2create
Which should run my program (this the first time that I try something like this…)
But the error which Im getting is:
no main manifest attribute, in /Users/i012/IdeaProjects/myproj/target/test.rts-1.0-SNAPSHOT.jar
What could be missing here ? which manifest attribute ?
The error is not coming from the class i’ve created …
i've created some META-INF/MANIFEST.MF not helping but maybe Its wrong
Upvotes: 10
Views: 60650
Reputation: 85
I had the same problem and it was solved by adding this plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.somepackage.CLASSWITHMAINMETHODE</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Upvotes: 1
Reputation: 12777
You need a main class to execute you application. Try the following. It worked for me.
Add the following code snippet to your pom.xml file if you are using maven build tool.
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.validator.App</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>
</plugins>
</build>
Upvotes: 2
Reputation: 51
in my case, I was using spring-boot but i did not mentioned my builder in my pom so i fixed it by:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Upvotes: 5
Reputation: 4307
If you're using the Maven assembly plug-in, or your IDE tooling is, you need a mainClass
element. This is what I use:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.foo.MyMainClass</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>
Upvotes: 12
Reputation: 1306
A manifest is a file in the path META-INF/MANIFEST.MF within the jar which defines attributes like the classpath and the main class for running the jar file.
The basic structure would be like:
Manifest-Version: 1.0
Created-By: 1.7.0_06 (Oracle Corporation)
You can define your entry point by adding the property Main-Class: classname
.
In order to create your jar file with a given manifest you can:
jar cfm MyJar.jar Manifest.txt MyPackage/*.class
to manually create a jar with the given manifest and classes.You can find out more about the jar manifest file here.
Upvotes: 4