I have a scala program that I would like to call from within django using subprocess:
encode_cmd = "/usr/local/share/scala/scala-2.10.0/bin/scala -cp /home/django/code/classes conn {}".format(self.id)
output = subprocess.Popen(encode_cmd, shell = True, stdout = subprocess.PIPE).stdout.read()
This code runs fine in the python shell, but when run as part of the normal webserver process it fails to find the scala dependencies (the scala class references the slick libraries for example) failing with the java.lang.NoClassDefFoundError.
I’ve tried specifying specific users as part of the mod_wsgi daemon process, but this makes no difference.
You should add jars in your command like that:
-cp /home/django/code/classes:/path/to/slick.jar, otherwise it only includes the .class’ and folders containing class files as per packages.You can always rely on the shell expansion if you have many jars:
/path/to/dependencies/*.jarAnother option is using SBT’s xsbt-start-script-plugin or Maven’s appassembler plugin to create a shell script