-1

I'm building a java application using Eclipse/Maven but keep getting a "no main manifest attribute, in xxx.jar" error message when I try to run the compiled jar. I've been through (or at least think I have so won't take offence if asked to try something in that thread again) everything in this Can't execute jar- file: "no main manifest attribute" thread. The main thing that matches is that my MANIFEST.MF doesn't contain any class information leading me to think that there's a problem with my pom.xml or some settings in Eclipse (Mars2). My pom.xml is below

<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>io.github.EmbeddedPi</groupId>
<artifactId>udpServerLED</artifactId>
<version>0.0.1</version>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>udpServerLED.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

and the main gist of the main source file is

package udpServerLED;
     public class Main {
         public Main () {}
     }

Full code can be seen at https://github.com/EmbeddedPi/udpServerLED

My gut feeling is that I've committed some newbie syntax faux pas in setting up the project framework but I just can't see it. My amateur attempts at writing software have up until now been aided by posts on here so thought I'd actually register to directly ask this.

Community
  • 1
  • 1
DaveW
  • 31
  • 6
  • did you configure the maven-jar-plugin like specified in the question you linked? – A_Di-Matteo Apr 25 '16 at 06:48
  • Yes and no. I included the parameters for the jar plugin albeit in the existing compiler plugin (this code is an adaptation of a Bukkit plugin which didn't previously need to be independently executed). Fixing this has me one step further as I now have a class in my manifest although it doesn't execute yet. I'm off to read and play some more and will report back. – DaveW Apr 26 '16 at 20:03
  • you need to configure the maven-jar-plugin for manifest configuration of the packaged jar, however to run it might most probably require also dependencies, hence you would need a fat-jar (or jar with dependencies), then you should use the maven-shade-plugin and configure the manifest entries in it – A_Di-Matteo Apr 26 '16 at 20:54
  • Just configuring the maven-jar-plugin fixed it thanks. I've added my new pom.xml in the solution. – DaveW Apr 26 '16 at 21:08

1 Answers1

2

pom.xml needs separate compiler and jar plugin sections as below.

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>                
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <mainClass>udpServerLED.Main</mainClass>
                </manifest>
            </archive>
        </configuration>
    </plugin>
</plugins>

Thanks for A. Di Matteo's comment above that pointed me in the right direction to fix this.

DaveW
  • 31
  • 6