Search code examples
eclipsemaven-2scalam2eclipse

Building jar with maven-scala-plugin


I created scala application and now I want to build jar. I run mvn package than I try to run jar by command

java -jar target/burner-1.0-SNAPSHOT.jar

and I see error:

Failed to load Main-Class manifest attribute from

How can I define Main-Class property? Do I need to create Manifest.mf? where? Or I need to have mainclass property somewhere in pom.xml?

Update: I have created src/main/resources/MANIFEST.MF file with contents

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: itsabear
Main-Class: ru.dmteam.App
Build-Jdk: 1.6.0_20

I did not forget line ending at the end of file. after mvn package I see new jar. I checked manifest.mf in this jar - it contains right main-class but when I type java -jar target/burner-1.0-SNAPSHOT.jar I still see an error Failed to load Main-Class manifest attribute from

My pom.xml http://pastie.org/1070483

UPDATE 2 I discovered that now there are two manifest.mf files in the jar. MANIFEST.MF and META-INF/MANIFEST.MF I moved my custom MANIFEST.MF to just created META-INF folder(in src/main/resources) but now mvn package overrides it while creating jar...


Solution

  • After creating a new maven project using the scala-archetype-simple archetype (A simple project that prints 'Hello World'), I needed to add the following to my pom.xml

       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-5</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <mainClass>test.App</mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    

    for the class test.App to run as desired when invoked with the command

    java -jar ./target/mytest-1.0-SNAPSHOT-jar-with-dependencies.jar
    

    After running the command

    mvn package