Well it turns out that on Linux if you
chmod +x
a scala script you can make it executable with a bit of shebang magic as shown by this complete, runnable script:#!/bin/sh exec scala $0 $@ !# println("Hello World"!")(You do have to make sure that "scala" is in your executable path.)
But what if you are using a scala script to control an existing Scala or Java system? It would be nice to express the CLASSPATH requirements in the script itself rather than depending on the calling environment to be configured correctly. Well, I came up with this convenient idiom to collect all the JAR files in a lib directory and add them to the CLASSPATH:
#!/bin/sh L=`dirname $0`/../lib cp=`echo $L/*.jar|sed 's/ /:/g'` exec scala -classpath $cp $0 $@ !# import com.my.special.World val world = new World world.helloThis assumes that all the required JAR files are in directory
../lib
relative to the script file.scalaclass
0 comments: on "How a Scala script can specify what JARs should be added to its CLASSPATH"
Post a Comment