我正在使用sbt 1.0.2。我的build.sbt是
name := "myprogram"
version := "0.1"
scalaVersion := "2.12.3"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test"
// https://mvnrepository.com/artifact/net.sf.py4j/py4j
libraryDependencies += "net.sf.py4j" % "py4j" % "0.10.6"
scalacOptions ++= Seq(
"-unchecked",
"-deprecation",
"-feature",
"-encoding", "UTF-8",
"-Xfuture",
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Ywarn-nullary-unit", // Warn when nullary methods return Unit.
"-Ywarn-unused", // Warn if a method or value is unused.
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
)
javacOptions ++= Seq("-source", "1.8", "-target", "1.8")
test in assembly := {}
assemblyJarName in assembly := "myprogram.jar"
exportJars := true
mainClass in Compile := Some("com.company.MyClass")
mainClass in assembly := Some("com.company.MyClass")
mainClass in(Compile, run) := Some("com.company.MyClass")
mainClass in(Compile, packageBin) := Some("com.company.MyClass")
似乎用sbt assembly
编译好了,其中一些输出是
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
[info] Including: py4j-0.10.6.jar
[info] Including: scala-library.jar
[info] Checking every *.class/*.jar file's SHA-1.
[info] Merging files...
[warn] Merging 'META-INF/MANIFEST.MF' with strategy 'discard'
[warn] Merging 'META-INF/maven/net.sf.py4j/py4j/pom.properties' with strategy 'discard'
[warn] Merging 'META-INF/maven/net.sf.py4j/py4j/pom.xml' with strategy 'discard'
[warn] Strategy 'discard' was applied to 3 files
进入命令行后,我得到了
$ java -jar myprogram.jar
no main manifest attribute, in myprogram.jar
我打开我的罐子,看着MANIFEST.MF
,找不到主要的那个:
Manifest-Version: 1.0
Implementation-Title: myprogram
Implementation-Version: 0.1
Specification-Vendor: default
Specification-Title: myprogram
Implementation-Vendor-Id: default
Specification-Version: 0.1
Implementation-Vendor: default
值得一提的是,我的程序主要是在Scala中,除了我的Java主类。
我需要改变什么?
答案 0 :(得分:2)
从您显示的日志中,我的猜测是 - 在其中一个包含的罐子的内容中 - 已经是META-INF/MANIFEST.MF
,而您的/由sbt汇编创建的 - 您的主要内容class被声明 - 被丢弃(我不是100%肯定,因为你显示的清单的内容似乎包含来自你的代码的东西)。
我认为这表明您的清单被丢弃了:
[警告]合并' META-INF / MANIFEST.MF'策略' discard'
我打赌那里已经有了META-INF / MANIFEST.MF'在py4j-0.10.6.jar
。
MergeStrategy.concat
的{{1}}策略。大致是:
META-INF/MANIFEST.MF