I have SBT Scala project who sends emails with some information to users. Everything works fine using IntelliJ to run it, but I need to build the project, put on the server and run from terminal.
In the first step I use below command to build the project:
sbt clean compile package
after that I try to run it by:
scala target/scala-2.12/project_name_sbt_2.12-0.1.jar
then I got error:
java.lang.ClassNotFoundException: javax.mail.Authenticator
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
It is command line app, I don’t use Tomcat and other containers. Construction is simple and easy. I have a main class like:
object MyApp extends App {new SomeService().run()}
I have build.sbt like:
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
"mysql" % "mysql-connector-java" % "5.1.16",
"org.jsoup" % "jsoup" % "1.11.2",
"joda-time" % "joda-time" % "2.10.1",
"org.apache.commons" % "commons-email" % "1.5"
)
Could you point me to the right direction to resolve that issue? What’s wrong?
2
Answers
Thanks for Markus Appel, Luis Miguel Mejia Suarez, and Mahmoud Hanafy. As you recommended I used assembly and it works fine for me.
I usually use this plugin to create the jar.
Try to add it to your plugins.sbt file
and run this command to create the jar:
and then try to run your jar again.