Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 872
Andrey Kuznetsov Avatar asked Aug 02 '10 03:08

Andrey Kuznetsov


People also ask

Can we use Maven with scala?

If you're familiar with Maven, you can go ahead with the Scala Maven Plugin.

What is scala Maven plugin?

The scala-maven-plugin is used for compiling/testing/running/documenting scala code in maven.


1 Answers

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
like image 62
Jon McAuliffe Avatar answered Oct 27 '22 18:10

Jon McAuliffe