How a Scala script can specify what JARs should be added to its CLASSPATH

  • strict warning: Only variables should be passed by reference in /home/eob/scalaclass.com/modules/book/book.module on line 560.
  • strict warning: Non-static method view::load() should not be called statically in /home/eob/scalaclass.com/sites/all/modules/views/views.module on line 842.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/eob/scalaclass.com/sites/all/modules/views/handlers/views_handler_argument.inc on line 745.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/eob/scalaclass.com/sites/all/modules/views/handlers/views_handler_filter.inc on line 589.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/eob/scalaclass.com/sites/all/modules/views/handlers/views_handler_filter.inc on line 589.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/eob/scalaclass.com/sites/all/modules/views/handlers/views_handler_filter_boolean_operator.inc on line 149.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/eob/scalaclass.com/sites/all/modules/views/plugins/views_plugin_row.inc on line 135.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/eob/scalaclass.com/sites/all/modules/views/plugins/views_plugin_row.inc on line 135.

The reason the Scala programming language has such a name is that it is meant to be scalable, i.e. good for both small scripts and large software systems. I am already convinced that Scala is as good, if not better than Java for the large-scale development, but what about the small scale?

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.hello

This assumes that all the required JAR files are in directory ../lib relative to the script file.

[This was originally posted on my blog.]

> omeprazole 40 mg price - buy misoprostol and mifepristone
- valtrex buy online no prescription - where to buy asacol - cell spy phone - generic levitra -