How to make jar file with sbt with external java jar file

I need to make jar file with set with external java jar file.

I made jar file by the following, while putting the external jar file in the myProject/lib folder, which is successful:

sbt compile
sbt package

However, executing the jar file created by this way as follows

scala myProject.jar

failed with the java.lang.ClassNotFoundException exception.

Whereas the project is executing well in Eclipse Scala IDE.

What I’m doing wrong here ?

You may have problem missing dependencies as scala package does only packs your artifact alone. This way, when running the jar, you need to add dependencies into classpath.
If you wish to build a standlone runnable jar, use sbt assembly instead.

When you run your code in sbt does it work?

In your build.sbt you need to have a line like this to load the external jar(s) from a custom folder at build time.

unmanagedResourceDirectories in Compile += {baseDirectory.value / "lib"}

The above line loads from the current_folder/lib all the jars when you run
sbt assembly or package.

I solved the problem. The problem was that sbt was not cleaned; that is, it was solved after executing sbt clean.

We have confirmed that after sbt clean, both of sbt compile ; sbt package and sbt assembly worked.

Also, we confirmed that it worked with or without adding unmanagedResourceDirectories in Compile += {baseDirectory.value / “lib”} in build.sbt.

Thank you for your answers.