views:

209

answers:

2

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

A: 

you can run the jar this way

scala -cp target/projectname-1.0-SNAPSHOT.jar

Joe Stein
This command opens scala interpreter console.
SMiX
+3  A: 

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
Jon McAuliffe
When I type mvn package I see error `'single' was specified in an execution, but not found in the pluin`'
SMiX
so now I can build working jar by command mvn assembly:assembly but I need to run it with command `java -cp target/file.jar -DmainClass ru.dmteam.App`. Is it possible to create jar with right manifest?
SMiX
The <executions> component should bind the assembly creation to the normal package phase, have you included it in your pom.xml? The <archive> entry should be configured to contained the <mainClass> ru.dmteam.App in your case.
Jon McAuliffe
Yes I included all in pom.xml - http://pastie.org/1071675
SMiX
When I changed maven version to 2.2-beta-3 all problems gone! Thanks.
SMiX