在Python Flask Cloud Foundry/IBM Cloud应用程序中添加Java/JRE/JVM [英] Add Java/JRE/JVM in Python Flask Cloud Foundry/IBM Cloud application
问题描述
我正在Cloud Foundry/IBM Cloud环境中运行python flask应用程序.在我的应用程序中,我尝试使用IBMDBPY-package连接到Cloud上的DB2 Warehouse.该软件包需要一个名为jaydebeapi的软件包才能运行.为了使jaydebeapi正常工作,我认为我需要以某种方式在服务器上安装JRE/JVM.我尝试添加服务器JRE 适用于基于Linux的操作系统,但也不起作用.在尝试上传Sever JRE之前我遇到的错误是:
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
并在项目的根目录中包含multi-buildpack.yml
并包含以下内容
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
和具有以下内容的apt.yml
:
---
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
在runtime.txt
文件中(也在项目的根目录中)是python的版本
python-3.6.6
In the runtime.txt
file, (also in the root of the project) is the version of python
python-3.6.6
不幸的是,JAVA已安装在您的home deps
目录中,因此,您必须在manifest.yml
中创建一个JAVA_HOME
环境变量.
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/
我还尝试通过这种方式将jre/bin添加到路径中
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
但是,对于我来说,推送完全消除了这一点,并仅安装了默认路径/bin;/usr/bin
,JAVA_HOME
足以使jaydebapi
与我拥有的jar
文件的数据库驱动程序一起使用.如果您需要此环境变量,
也许尝试使用python
操作系统软件包在启动过程中发出命令来修改路径.
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.
这篇关于在Python Flask Cloud Foundry/IBM Cloud应用程序中添加Java/JRE/JVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!