Do you know why “sbt run” can success, but running “scala program.scala” directly got the error following?
$ scala target/scala-2.13/hivedb_2.13-0.1.jar
java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
sbt run can be fine:
$ sbt run
[success] Total time: 2 s, completed Mar 1, 2022, 11:30:43 AM
This is a simple Hive client using the only package:
You would need to run scala with a -classpath argument with the paths of all the dependency JARs, including any transitive dependencies.
In sbt, export dependencyClasspath will show you what that looks like. (Note that the output will include Scala library JARs which you don’t need to include when running the code with the scala command, but do need to include if you’re running it with the java command.)
may I ask for the complicated java dependencies how do you deploy your program?
It has no possible to ask every server box to install sbt and run scala program via sbt run.
Yes, but the target machine needs a JDK and Scala or maybe Ammonite.
What kind of issues?
If missing dependencies, you need to provide them somehow.
Or if rather you have mismatches of versions then you need to review what are the duplicated entries in the class path.
No idea what Resin is, but yes you can create containers like Docker; that is probably what most of us do.
And for that you have a couple of options:
Using sbt-assembly + a custom Dockerfile
And call docker build after a sbt assembly
Using sbt-native-packager + its Docker plugin.
You may also explore using Graal to create native images. This is great for small scripts / programs and CLI tools.