使用 maven-scala-plugin 构建 jar

发布于 2024-09-12 01:43:47 字数 1056 浏览 3 评论 0原文

我创建了 scala 应用程序,现在我想构建 jar。 我运行 mvn package 比我尝试通过命令

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

运行 jar并看到错误:

无法加载 Main -Class 清单属性来自

如何定义 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。我检查了这个 jar 中的 manifest.mf - 它包含正确的主类,但是当我输入 java -jar target/burner-1.0-SNAPSHOT.jar 时,我仍然看到错误 Failed to load Main 的类清单属性

- 来自 我的 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 时覆盖它...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请远离我 2024-09-19 01:43:48

使用 scala-archetype-simple 原型创建新的 Maven 项目(一个打印“Hello World”的简单项目)后,我需要将以下内容添加到

   <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 的 pom.xml 中使用命令调用时根据需要运行

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

运行命令后

mvn package

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
忘羡 2024-09-19 01:43:48

你可以这样运行jar

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

you can run the jar this way

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文