89281

Maven (Eclipse plugin and mvn) not including main class with pom.xml setup

Question:

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!

Answer1:

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!

Answer2:

Have you tried running:

<blockquote>

mvn clean install exec:java

</blockquote>

In the same folder as your pom.xml (from the root of your project)?

Recommend

  • Maven JAR Plugin 3.0.2 Error: You have to use a classifier to attach supplemental artifacts to the p
  • Trying to get Spring/Consul/Vault to work together
  • Spring boot deploy wildfly doesn't work
  • printf, saying, getName setName
  • Using the maven-remote-resources-plugin and specifying the resourcesDirectory
  • String Split sql function only returning first word in string
  • Muliple upload php script and store in mysql database
  • Xpath how to get element by index AND attribute
  • Spring custom user details service null pointer exception
  • Maven + Surefire/Failsafe - forkMode=“perthread” is not working … a workaround?
  • After switching from Spring Boot 1.2.8 to 1.3.2 application magically stops working
  • SessionInformation expiration doesn't lead to user log out from system
  • Reading contents of a managed bean with reflection in a JSF application
  • Savon soap body problem
  • How to set default security access for a Page Type in Silverstripe?
  • PrimeFaces p:fileUpload Listener method is never invoked for mode=“simple”
  • Get Users in Group from Azure AD via Microsoft Graph
  • how to exclude java sources from a third party jar?
  • Maven, ActionBarSherlock v4 and Roboguice v2 - How do I get it to build?
  • Filtering SPARQL results by day and month
  • Regarding client side code generation from WSDL
  • How can I create one checksum of two files in Maven to use it in the name of a directory
  • How to call BeanFactoryPostProcessor.postProcessBeanFactory method when use Spring with XML configur
  • how to ignore xml namespaces?
  • Should a web service response include empty values?
  • Is it possible to define rest argument in OCaml?
  • Using Laravel 5.4 pusher
  • How to convert SOAP response with xsi values to json in WSO2esb
  • Oledb connection string for excel files
  • Jetty 9 HashLoginService
  • java inputstream
  • Counter field in MS Access, how to generate?
  • Numpy divide by zero. Why?
  • Arrays break string types in Julia
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Converting MP3 duration time
  • Conditional In-Line CSS for IE and Others?
  • How can I use threading to 'tick' a timer to be accessed by other threads?