Problem
The problem is that when you run console from SBT you're inside the project space, which includes your libraries.
But when you execute the script on its own, it is in the system space, and the libraries aren't present.
How to fix
Couple of options here:
- Create an Uber JAR, instead of an script.
- Add those libraries to your CLASSPATH.
- Use Ammonite.
Uber JAR
The most common solution to this problem in general is to create an Uber JAR. It is also the most portable one, because now you have a jar with all its dependencies included, so you can run it anywhere - Also, because it is a Jar, you don't even need Scala anymore, just a JRE.
If you're going this way, check sbt-assembly. However, since you have probably a small script, going this way could be an overkill to your problem - but keep in mind that for larger projects this is the canonical solution.
CLASSPATH
The CLASSPATH env variable indicates Java where to search for classes (usually contained in libraries - Jars), so you only need to update this variable to include the missing libraries, you could do this by creating a folder (e.g. /opt/jars/) and downloading all jars to that folder, and then adding a line like one this in your .bashrc
file, to make sure the env var is updated every time yo open a shell.
export CLASSPATH="/opt/jars/*:$CLASSPATH"
PS: Since SBT already downloaded the jars to the .ivy2/cache/
folder, you could point your CLASSPATH to that directory, but take care with multiple versions of the same Jar.
Ammonite
Ammonite is like a Scala RELP with super powers, one of its main advantages is to import Jars from ivy, which is exactly what you need. Also Ammonite can be used for scala scripts. So probably worth it giving a try.