簡體   English   中英

使用maven-scala-plugin構建jar

[英]Building jar with maven-scala-plugin

我創建了scala應用程序,現在我想構建jar。 我運行mvn package比嘗試運行jar by命令

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

我看到錯誤:

Failed to load Main-Class manifest attribute from

如何定義Main-Class屬性? 我需要創建Manifest.mf嗎? 哪里? 或者我需要在pom.xml中的某個地方使用mainclass屬性?

更新:我已經創建了包含內容的src / main / resources / MANIFEST.MF文件

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

我沒有忘記在文件末尾的行結尾。 mvn package我看到了新罐子。 我在這個jar中檢查了manifest.mf - 它包含正確的主類但是當我輸入java -jar target/burner-1.0-SNAPSHOT.jar我仍然看到一個錯誤Failed to load Main-Class manifest attribute from

我的pom.xml http://pastie.org/1070483

更新2我發現現在jar中有兩個manifest.mf文件。 MANIFEST.MF和META-INF / MANIFEST.MF我將我的自定義MANIFEST.MF移動到剛剛創建的META-INF文件夾(在src / main / resources中)但是現在mvn package在創建jar時覆蓋了它...

在使用scala-archetype-simple archetype(一個打印'Hello World'的簡單項目)創建一個新的maven項目之后,我需要將以下內容添加到我的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>

對於類test.App ,在使用該命令調用時按需運行

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

運行命令后

mvn package

你可以用這種方式運行jar

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM