I have just started learning how to use m2eclipse. What I am trying to do is make a very simple program (Hello, World) and turn it into an executable jar. The java code itself is:
public class Speak {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Meow!");
}
}
which runs fine as a Java application. I then try to use Maven to build the program, which it does, but then when I try to run the .jar it tells me “Failed to load Main-Class attribute from …”. This is the .pom that m2eclipse generated when I started the project:
<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>org.felines</groupId>
<artifactId>tabbies</artifactId>
<version>0.0</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<type>maven-plugin</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
I have tried modifying the .pom, like so:
<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>org.felines</groupId>
<artifactId>tabbies</artifactId>
<version>0.0</version>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<manifest>
<mainClass>org.felines.Speak</mainClass>
<packageName>org.felines</packageName>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${pom.url}</url>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Now it says “Could not find the main class: org.felines.Speak. Program will exit.” Any ideas? 🙁
Thank you for your time!
In your pom.xml you state that the main class should be
org.felines.Speak. But the class is actually in the default package, meaning no package definition. So either set the package toorg.felinesin the class implementation or change yourmainClassentry in the pom.xml toSpeakalone. Then the necessary information to start the jar should be available.