Reputation: 1467
I know i can use sbt to avoid all this problem but just for knowledge sake. I am not sure why i can compile the code but not able to run it.
My directory structure is as such:
$ ls io_monad/*
io_monad/Test.scala
io_monad/classes:
io_monad
io_monad/lib:
cats-core_2.12-0.9.0.jar cats-effect_2.12-0.7.jar
Simple Test.scala file
package io_monad
import cats.effect.IO
object Test extends App {
val program:IO[Unit] = for {
_ <- IO { println("First name?") }
firstName <- IO { scala.io.StdIn.readLine }
_ <- IO { println(s"Last name?") }
lastName <- IO { scala.io.StdIn.readLine }
_ <- IO { println(s"First: $firstName, Last: $lastName") }
} yield ()
program.unsafeRunSync()
}
Compiling successful
$ scalac -cp "io_monad/lib/cats-core_2.12-0.9.0.jar:io_monad/lib/cats-effect_2.12-0.7.jar" -d io_monad/classes io_monad/Test.scala
But not the running of app
$ scala -cp "io_monad/lib/cats-core_2.12-0.9.0.jar:io_monad/lib/cats-effect_2.12-0.7.jar:io_monad/classes/" io_monad.Test
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
java.lang.ClassNotFoundException: cats.kernel.Semigroup
Upvotes: 0
Views: 903
Reputation: 15086
At compile time your code only depends on the class files in those 2 jars on your classpath, but at runtime the code in cats-core
or cats-effect
also requires classes from cats-kernel
. This isn't a problem during compilation because the code that depends on cats-kernel
is already compiled to bytecode.
Upvotes: 4