LaVOZs

The World’s Largest Online Community for Developers

'; linux - Python script can't reach .jar file inside Docker image - LavOzs.Com

I'm trying to dockerizing some flask app that I create.

I need to access a java file using startJVM() in the Python script I created. The code below works fine on my local terminal and it can detect the path of the file with the ".jar" extension.

ZEMBEREK_PATH = os.path.abspath("zemberek-full.jar")

startJVM(getDefaultJVMPath(), '-ea', f'-Djava.class.path={ZEMBEREK_PATH}', convertStrings=False)

But when I run this in docker image, I guess the path variable cannot find the file with the extension ".jar", so the program gives an error.

Traceback (most recent call last):
  File "app.py", line 28, in <module>
    startJVM(getDefaultJVMPath(), '-ea', f'-Djava.class.path={ZEMBEREK_PATH}', convertStrings=False)
  File "/usr/local/lib/python3.7/site-packages/jpype/_core.py", line 337, in getDefaultJVMPath
    return finder.get_jvm_path()
  File "/usr/local/lib/python3.7/site-packages/jpype/_jvmfinder.py", line 160, in get_jvm_path
    jvm = method()
  File "/usr/local/lib/python3.7/site-packages/jpype/_jvmfinder.py", line 215, in _get_from_known_locations
    for home in self.find_possible_homes(self._locations):
  File "/usr/local/lib/python3.7/site-packages/jpype/_jvmfinder.py", line 120, in find_possible_homes
    for childname in sorted(os.listdir(parent)):
FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/jvm'

I checked the files in the Docker image. "zemberek-full.jar" is seamlessly included in the image.

Is there a solution you can offer against this problem I am having?

I would like to thank in advance, everyone who took the time to solve this problem. :)

This Is My Dockerfile

FROM python:3.7


ARG DEBIAN_FRONTED=noninteractive


RUN apt-get update && apt-get install -y --no-install-recommends apt-utils > /dev/null

RUN apt-get install -y build-essential tcl

RUN apt-get install -y systemd-sysv

RUN apt-get update  > /dev/null

RUN apt-get install  -y wget > /dev/null

RUN apt-get install  -y zip > /dev/null

RUN apt-get install  -y libaio1 > /dev/null

RUN apt-get update > /dev/null

RUN apt-get install  -y alien > /dev/null

WORKDIR /

RUN mkdir /app

WORKDIR /app

COPY . .

RUN pip install -r requirements.txt

CMD ["python", "app.py"] 

You don't have JVM installed in your Docker instance. Add this line to your Dockerfile to install it:

RUN apt-get install -y openjdk-11-jdk;
Related
How do I copy a file in Python?
Why can't Python parse this JSON data?
How does one remove an image in Docker?
Where are Docker images stored on the host machine?
How do I import modules in pycharm?
Copying files from Docker container to host
Copying files from host to Docker container
What is the difference between a Docker image and a container?
How to copy Docker images from one host to another without using a repository
From inside of a Docker container, how do I connect to the localhost of the machine?