I have encountered with this error while building Scala JAR file, please help me.
build.sbt file:
cat > databricks_jar_test/build.sbt << EOF
ThisBuild / scalaVersion := "2.12.14"
ThisBuild / organization := "com.nm.udf"
lazy val udfDecrypt = (project in file("."))
.settings(
name := "udfDecrypt"
)
// https://mvnrepository.com/artifact/org.scala-lang/scala-library
libraryDependencies += "com.macasaet.fernet" % "fernet-java8" % "1.5.0"
// https://mvnrepository.com/artifact/org.apache.hive/hive-exec
libraryDependencies += "org.apache.hive" % "hive-exec" % "3.1.2"
Scala file
cat > databricks_jar_test/src/main/scala/udfDecrypt.scala << EOF
package com.nm.udf;
import java.time.Duration;
import java.time.Instant;
import com.macasaet.fernet.{Key, StringValidator, Token};
import org.apache.hadoop.hive.ql.exec.UDF;
import java.time.{Duration, Instant};
class Validator extends StringValidator {
override def getTimeToLive() : java.time.temporal.TemporalAmount = {
Duration.ofSeconds(Instant.MAX.getEpochSecond());
}
}
class udfDecrypt extends UDF {
def evaluate(inputVal: String, sparkKey : String): String = {
if( inputVal != null && inputVal!="" ) {
val keys: Key = new Key(sparkKey)
val token = Token.fromString(inputVal)
val validator = new Validator() {}
val payload = token.validateAndDecrypt(keys, validator)
payload
} else return inputVal
}
}
cd databricks_jar_test/
sbt compile
cd databricks_jar_test/
sbt "run Hello World\!"
# Hello, World!
[error] java.lang.RuntimeException: No main class detected. [error] at scala.sys.package$.error(package.scala:30) [error] stack trace is suppressed; run 'last Compile / bgRun' for the full output [error] (Compile / bgRun) No main class detected. [error] Total time: 3 s, completed Jun 1, 2023, 3:06:00 PM
CalledProcessError Traceback (most recent call last) <ipython-input-11-2a66b8e4a500> in <cell line: 1>() 1 get_ipython().run_cell_magic('bash', '', 'cd databricks_jar_test/\nsbt "run Hello World\!"\n# Hello, World! \n')
4 frames /usr/local/lib/python3.10/dist-packages/google/colab/_shell.py in run_cell_magic(self, magic_name, line, cell) 332 if line and not cell: 333 cell = ' ' 334 return super().run_cell_magic(magic_name, line, cell) 335 336
/usr/local/lib/python3.10/dist-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell) 2471 with self.builtin_trap: 2472 args = (magic_arg_s, cell) 2473 result = fn(*args, **kwargs) 2474 return result 2475
/usr/local/lib/python3.10/dist-packages/IPython/core/magics/script.py in named_script_magic(line, cell) 140 else: 141 line = script 142 return self.shebang(line, cell) 143 144 # write a basic docstring:
<decorator-gen-103> in shebang(self, line, cell)
/usr/local/lib/python3.10/dist-packages/IPython/core/magic.py in <lambda>(f, *a, **k) 185 # but it's overkill for just that one bit of state. 186 def magic_deco(arg): 187 call = lambda f, *a, **k: f(*a, **k) 188 189 if callable(arg):
/usr/local/lib/python3.10/dist-packages/IPython/core/magics/script.py in shebang(self, line, cell) 243 sys.stderr.flush() 244 if args.raise_error and p.returncode!=0: 245 raise CalledProcessError(p.returncode, cell, output=out, stderr=err) 246 247 def _run_script(self, p, cell, to_close):
CalledProcessError: Command 'b'cd databricks_jar_test/\nsbt "run Hello World\!"\n# Hello, World! \n'' returned non-zero exit status 1.
This is for the encryption. I have tried in Databricks and Colab, same problem.