sbt / sbt-onejar

Packages your project using One-JAR™
MIT License
268 stars 45 forks source link

Failed to run a jar in Docker #37

Closed a-panchenko closed 6 years ago

a-panchenko commented 6 years ago

I have an sbt project with a very basic class. It works perfectly but when I'm trying to run it in Docker using simple docker run imagename command it throws

Error: Could not find or load main class java -jar scala_test_trash_2.11-1.0-one-jar.jar

Main class:

package com

object Main extends App {
  println("Testing hello world.")
}

build.sbt:

import com.github.retronym.SbtOneJar
import com.github.retronym.SbtOneJar.oneJar
import sbt.Keys.mainClass

name := "scala_test_trash"

version := "0.1"

scalaVersion := "2.11.12"

lazy val rootProject = (project in file("."))
  .settings(
    Seq(exportJars := true),
    SbtOneJar.oneJarSettings,
    libraryDependencies ++= Seq(
      "com.google.cloud" % "google-cloud-pubsub" % "0.34.0-beta",
      "com.sendgrid" % "sendgrid-java" % "2.2.2"
    ),
    mainClass in oneJar := Some("com.Main")
  )

plugins.sbt:

addSbtPlugin("org.scala-sbt.plugins" % "sbt-onejar" % "0.8")

Dockerfile:

FROM gcr.io/google_appengine/openjdk
WORKDIR /test_service
ADD ./target/scala-2.11/scala_test_trash_2.11-0.1-one-jar.jar /test_service
CMD ["java -jar scala_test_trash_2.11-1.0-one-jar.jar"]