I am running a python flask application in a Cloud Foundry/IBM Cloud-environment. In my application I try to connect to DB2 Warehouse on Cloud with the IBMDBPY-package. This packages needs a package called jaydebeapi to be able to run. For the jaydebeapi to work I think I need JRE/JVM somehow installed on the server. I tried adding the Server JRE for Linux based OS, but it didn't work either. My error I got before I tried to upload the Sever JRE was this:
idadb = IdaDataBase(dsn=jdbc) #Establish a connection to our DB2-service
1/20/2018 12:05:45 PM ERR undefined File "/home/vcap/deps/0/python./lib/python2.7/site-packages/ibmdbpy/base.py", line 282, in __init__
1/20/2018 12:05:45 PM ERR undefined jpype.startJVM(jpype.getDefaultJVMPath(), '-Djava.class.path=%s' % jarpath)
1/20/2018 12:05:45 PM ERR undefined File "/home/vcap/deps/0/python/lib/python2.7/site-packages/jpype/_core.py", line 114, in get_default_jvm_path
1/20/2018 12:05:45 PM ERR undefined return finder.get_jvm_path()
1/20/2018 12:05:45 PM ERR undefined File "/home/vcap/deps/0/python/lib/python2.7/site-packages/jpype/_jvmfinder.py", line 121, in get_jvm_path
1/20/2018 12:05:45 PM ERR undefined jvm = method()
1/20/2018 12:05:45 PM ERR undefined File "/home/vcap/deps/0/python/lib/python2.7/site-packages/jpype/_jvmfinder.py", line 164, in _get_from_known_locations
1/20/2018 12:05:45 PM ERR undefined for home in self.find_possible_homes(self._locations):
1/20/2018 12:05:45 PM ERR undefined File "/home/vcap/deps/0/python/lib/python2.7/site-packages/jpype/_jvmfinder.py", line 95, in find_possible_homes
1/20/2018 12:05:45 PM ERR undefined for childname in sorted(os.listdir(parent)):
1/20/2018 12:05:45 PM ERR undefined OSError: [Errno 2] No such file or directory: '/usr/lib/jvm'
1/20/2018 12:05:46 PM OUT undefined Exit status 1
Does anyone know how I can solve this?
After much trial and error, the solution that worked for me was a multi build pack deployment as described below:
cf push -b https://github.com/cloudfoundry/multi-buildpack
and in the root of your project include a multi-buildpack.yml
with the following
buildpacks:
- https://github.com/cloudfoundry/apt-buildpack
- https://github.com/cloudfoundry/python-buildpack
and an apt.yml
with the following:
---
packages: openjdk-8-jre
repos: deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu trusty main
keys: https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xEB9B1D8886F44E2A
In the runtime.txt
file, (also in the root of the project) is the version of python
python-3.6.6
Unfortunately, JAVA gets installed in your home deps
directory and as such you'll have to create a JAVA_HOME
environment variable in the manifest.yml
.
JAVA_HOME: /home/vcap/deps/0/apt/usr/lib/jvm/java-8-openjdk-amd64/jre/
I also tried to add jre/bin to the path this way
PATH: /bin:/usr/bin:/home/vcap/deps/0/apt/usr/lib/jvm/java-8-openjdk-amd64/jre/bin
However the push wipes this out and installs only the default path /bin;/usr/bin
fortunately for me, JAVA_HOME
was enough to get jaydebapi
to work with the database driver for the jar
files I had. If you need this environment variable,
maybe try using the python
os package to issue a command to modify the path as part of the startup.