我有一个包含程序集插件的build.sbt文件。直到最近的构建,Main-Class属性被包含在组装的far jar中,但突然间,情况不再如此。
当我尝试运行jar时,我得到了无法模仿的东西:
no main manifest attribute, in ./target/scala-2.10/foo-0.3.0-SNAPSHOT.jar
但是从sbt控制台运行,运行正常。
我的build.sbt目前看起来像这样(程序集中的mainClass试图强制向程序集插件指示它确实应该包含,虽然我注意到在插件源代码中,它看起来像是在检查指定的那个无论如何都要跑。)
import AssemblyKeys._
name := "foo"
version := "0.3.0-SNAPSHOT"
organization := "com.mycompany.myproduct"
scalaVersion := "2.10.4"
mainClass in (Compile, run) := Some("ProcessRelogger")
mainClass in assembly := Some("ProcessRelogger")
assemblySettings
libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.10" % "1.9.2" % "test",
"ch.qos.logback" % "logback-classic" % "1.0.9",
"com.typesafe.akka" %% "akka-actor" % "2.2.4",
"joda-time" % "joda-time" % "2.3",
"com.rabbitmq" % "amqp-client" % "3.3.4",
"org.scalaz" % "scalaz-core_2.10" % "7.0.6",
"com.typesafe.slick" %% "slick" % "2.0.2",
"postgresql" % "postgresql" % "9.1-901.jdbc4",
"com.escalatesoft.subcut" %% "subcut" % "2.0"
)
当我解压缩jar文件,并检查META-INF / MANIFEST.MF时,没有包含Main-Class:属性。
答案 0 :(得分:2)
尝试使用最新版本的sbt-assembly 0.11.2重现此问题。
<强>项目/ build.properties 强>
sbt.version=0.13.7-M3
<强>项目/ assembly.sbt 强>
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
<强> build.sbt 强>
import AssemblyKeys._
assemblySettings
scalaVersion := "2.11.2"
<强>的src /主/阶/ Main.scala 强>
object HelloApp extends App {
println("Hello")
}
将上述所有文件放在一个项目中:
> about
[info] Updating {file:/Users/jacek/sandbox/sbt-assembly/}sbt-assembly...
[info] Resolving jline#jline;2.12 ...
[info] Done updating.
[info] This is sbt 0.13.7-M3
[info] The current project is {file:/Users/jacek/sandbox/sbt-assembly/}sbt-assembly 0.1-SNAPSHOT
[info] The current project is built against Scala 2.11.2
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, com.typesafe.sbteclipse.plugin.EclipsePlugin, net.virtualvoid.sbt.graph.Plugin, com.github.tototoshi.sbt.musical.Plugin, com.timushev.sbt.updates.UpdatesPlugin, sbtassembly.Plugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
> assembly
[info] Updating {file:/Users/jacek/sandbox/sbt-assembly/}sbt-assembly...
[info] Resolving jline#jline;2.12 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/jacek/sandbox/sbt-assembly/target/scala-2.11/classes...
[info] Including: scala-library-2.11.2.jar
[info] Checking every *.class/*.jar file's SHA-1.
[info] Merging files...
[warn] Merging 'META-INF/MANIFEST.MF' with strategy 'discard'
[warn] Strategy 'discard' was applied to a file
[info] SHA-1: a5c09d7626fe19f4e3cd98d709966a77f127b048
[info] Packaging /Users/jacek/sandbox/sbt-assembly/target/scala-2.11/sbt-assembly-assembly-0.1-SNAPSHOT.jar ...
[info] Done packaging.
[success] Total time: 4 s, completed Oct 8, 2014 9:27:41 AM
> eval "unzip -p target/scala-2.11/sbt-assembly-assembly-0.1-SNAPSHOT.jar META-INF/MANIFEST.MF" !
Manifest-Version: 1.0
Implementation-Title: sbt-assembly
Implementation-Version: 0.1-SNAPSHOT
Specification-Vendor: default
Specification-Title: sbt-assembly
Implementation-Vendor-Id: default
Specification-Version: 0.1-SNAPSHOT
Main-Class: HelloApp
Implementation-Vendor: default
[info] ans: Int = 0
答案 1 :(得分:0)
这并不回答原始问题的“原因”,但正如其他评论所提到的,如果您引入了另一个main
(例如,间接通过另一个对象),则会发生这种情况。
因此,您可以在build.sbt中明确定义它:
mainClass in assembly := Some("path.to.intended.Main") // object with main
答案 2 :(得分:0)
在(编译,运行)中尝试注释掉mainClass:= Some(“ProcessRelogger”)
]$ sbt clean assembly
]$ java -jar target/xxx.jar