1

I am trying to build a project in Java that should run if executed with double click. That's not been working so I debugged with cmd and there was no main class entry in the manifest.

So i added the contents of this answer (adopted to my application): Missing Main-Class attibute in MANIFEST.MF in Maven generated jar file

I am using jenkins as build platform and have tried executing with mvn clean install and mvn clean package.

pom.xml:

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>de.progii</groupId>
  <artifactId>pong</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>pong</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.1.1</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>de.progii.pong.App</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>
Marvin
  • 129
  • 1
  • 13
  • 1
    Please add your `pom.xml` to your question. – J Fabian Meier May 02 '19 at 12:10
  • @JFMeier done it, thanks. – Marvin May 02 '19 at 12:44
  • Why do you have two `mainClass` entries? – Mike Harris May 02 '19 at 12:45
  • @MikeHarris I copied a git history commit and overlooked the removed line. Edited it, thanks. – Marvin May 02 '19 at 12:48
  • It looks OK to me. What is the exact message you get when you run it from the command line (for ex. with `java -jar target/pong-0.0.1-SNAPSHOT.jar`)? Are you sure that the `de.progii.pong.App` class has a `main` method properly defined? – Mike Harris May 02 '19 at 14:42
  • @MikeHarris the message is "kein Hauptmanifestattribut, in pong-0.0.1-SNAPSHOT.jar" which is equivalent to the english expression "no main manifest attribute, in pong-0.0.1-SNAPSHOT.jar" – Marvin May 02 '19 at 19:40
  • @MikeHarris Yes, its defined in there as its the maven archtype quickstart. If exported to runnable jar with eclipse it works just fine, but jenkins as buildserver is inevitable – Marvin May 02 '19 at 19:41
  • I partly fixed the problem. The problem is not the maven jar plugin, its jenkins. It simply archives the wrong build. The artifact available for download seems to be archived before the maven jar plugin does the job. If I connect with sftp to the workingspace/target folder I can download the artifact with the same name as the artifact at the jenkins download page but execute it successfully! – Marvin May 06 '19 at 08:22

1 Answers1

0

I partly fixed the problem. The problem is not the maven jar plugin, its jenkins. It simply archives the wrong build. The artifact available for download seems to be archived before the maven jar plugin does the job. If I connect with sftp to the workingspace/target folder I can download the artifact with the same name as the artifact at the jenkins download page but execute it successfully!

edit

With the latest Update to Jenkins its working correctly

Community
  • 1
  • 1
Marvin
  • 129
  • 1
  • 13