I am very aware that this covers the same error and output Caused by: java.lang.ClassNotFoundException
.
The distinction here is i’m not using Java, I’m using Scala. I have not seen a question that solves the .ClassNotFoundException for Scala. I’ve tried:
- specify MANIFEST.MF
john@oak:~/IdeaProjects/sss/src/main/scala$ jar -cvfm myJar.jar META-INF/MANIFEST.MF core/LoadSymbol.scala
added manifest
adding: core/LoadSymbol.scala(in = 221) (out= 158)(deflated 28%) # success
john@oak:~/IdeaProjects/sss/src/main/scala$ java -jar myJar.jar # failure
Error: Could not find or load main class core.LoadSymbol
Caused by: java.lang.ClassNotFoundException: core.LoadSymbol
- specfiy classpath and MANIFEST.MF
john@oak:~/IdeaProjects/sss/src/main/scala$ java -jar -classpath . myJar.jar META-INF/MANIFEST.MF core/LoadSymbol.scala # looks correct, bad syntax
Error: Could not find or load main class myJar.jar
Caused by: java.lang.ClassNotFoundException: myJar.jar
- Using
jar [options]
(notice the first command succeeds without specifying MANIFEST.MF)
john@oak:~/IdeaProjects/sss/src/main/scala$ jar cfe myJar.jar LoadSymbol core/LoadSymbol.scala
john@oak:~/IdeaProjects/sss/src/main/scala$ java -jar myJar.jar
Error: Could not find or load main class LoadSymbol
Caused by: java.lang.ClassNotFoundException: LoadSymbol
john@oak:~/IdeaProjects/sss/src/main/scala$ jar -cvfm myJar.jar core/LoadSymbol.scala
java.io.IOException: invalid header field
at java.base/java.util.jar.Attributes.read(Attributes.java:409)
at java.base/java.util.jar.Manifest.read(Manifest.java:232)
at java.base/java.util.jar.Manifest.<init>(Manifest.java:82)
at java.base/java.util.jar.Manifest.<init>(Manifest.java:74)
at jdk.jartool/sun.tools.jar.Main.run(Main.java:268)
at jdk.jartool/sun.tools.jar.Main.main(Main.java:1686)
john@oak:~/IdeaProjects/sss/src/main/scala$
File system tree layout
total 40
drwxrwxr-x 6 john john 4096 Aug 18 20:40 .
drwxrwxr-x 5 john john 4096 Aug 15 22:02 ..
-rw-rw-r-- 1 john john 176 Aug 11 21:40 Constants.scala
drwxrwxr-x 2 john john 4096 Aug 16 11:45 core
-rw-rw-r-- 1 john john 47 Aug 16 22:20 manifest.txt
drwxrwxr-x 2 john john 4096 Aug 16 22:29 META-INF
-rw-rw-r-- 1 john john 659 Aug 18 20:40 myJar.jar
drwxrwxr-x 2 john john 4096 Aug 16 11:17 schemas
drwxrwxr-x 2 john john 4096 Jul 31 18:20 technical
contents of META-INF/MANIFEST.MF
Manifest-Version: 1.0
Main-Class: core/LoadSymbol
uses the file: core/LoadSymbol.scala, contents of core/LoadSymbol.scala:
package core
import core.EndpointDataLoader.{fromAPI, toDatabase}
object LoadSymbol extends App {
private val table = System.getenv("FOO")
val symbolDataFrame = fromAPI()
toDatabase(symbolDataFrame, table)
}
I’ve tried setting source files/ folders
I’ve found that Java versions can cause issues: – Answered on Sep 20, 2020 (not recent enough) that says to use Java 8, and there were on the higher version 14. Java I’m using 11.0.23
2