问题
I've been trying to work this out for the last few hours and I've got nowhere. I've just installed the Maven for Eclipse plugin (M2E, I think) and also the maven too, mvn. I've created a very simple Hello World project and am trying to get the built jar to run on using: java -jar pimidi-0.0.1-SNAPSHOT.jar
Regardless of what I try, I always get the same error: no main manifest attribute, in target/pimidi-0.0.1-SNAPSHOT.jar
Here is my pom.xml:
<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>com.dan</groupId>
<artifactId>pimidi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>pimidi</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>1.5</wtpversion>
</configuration>
</plugin>
<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>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.dan.pimidi.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
I've tried countless different options within the manifest nodes of the POM (classpath, manifest location), different plugins (assembly, compile, etc) to no avail. On looking at the effective POM in Eclipse, I can see that maven-jar-plugin is already included from a higher-level POM an any changes to the project POM are omitted.
Does anyone have any ideas about how to get this working? Apologies if this question lacks detail - I have expired my mental power for this evening. Any assistance would be greatly appreciated!
回答1:
After following numerous pieces of advice, I decided to delete my project (which was only a mvn archetype), uninstall eclipse (to remove the m2e plugin) along with my ~/.m2 folder. I then did everything from the command line:
mvn archetype:generate -DgroupId=com.dan.pimidi -DartifactId=pimidi -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Added this to my pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.dan.pimidi.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Then a quick:
mvn clean package
And a:
java -jar target/nameofjar.jar
Solved my problem!
回答2:
Have you tried running:
mvn clean install exec:java
In the same folder as your pom.xml (from the root of your project)?
来源:https://stackoverflow.com/questions/19126636/maven-eclipse-plugin-and-mvn-not-including-main-class-with-pom-xml-setup