Unable to use java in docker container - java

I am trying to use dask-sql in my python code which needs JAVA in the docker container.
this is my docker file
RUN apk update
RUN apk add make automake gcc g++ subversion python3-dev
RUN apk add openjdk11
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk/
RUN export JAVA_HOME
RUN export LD_LIBRARY_PATH=/usr/lib/jvm/java-11-openjdk/lib/libjava.so:/usr/lib/jvm/java-11-openjdk/lib/server/libjvm.so
this is the code in my python file
from dask_sql import Context
c = Context()
print(c.sql('''some SQL query''')
but I am getting below error while running the code
An error occurred during the initialization of the VM
Unable to load native library: Error loading shared library libjvm.so: No such file or directory (needed by /usr/lib/jvm/java-11-openjdk/lib/libjava.so)
This is the actual path for both these files:
bash-5.1# find / -name libjava.so
/usr/lib/jvm/java-11-openjdk/lib/libjava.so
bash-5.1# find / -name libjvm.so
/usr/lib/jvm/java-11-openjdk/lib/server/libjvm.so

Related

Build Docker Image with Java and Node.js together (Error : java: not found )

I've an API application that run both node and java files(jar) together. When I run the application locally it works, but once I create a docker image for it, I got an error from the postman .
parsingError: Command failed: java -jar Binary\***.jar -s Files\*** -v -j
/bin/sh: 1: java: not found
I believe that I'm missing the jave configuration in docker file but I don't know how to put the configuration for java and node together. any help will be appricatited!
Here is the Docker config.
FROM node:14.18.1
WORKDIR /code
ENV PORT 3000
COPY package.json /code/package.json
RUN npm install
COPY . /code
CMD ["node","app.js"]
Note: I'm using Temurin JDK
Maybe inside node:14.18.1 there is no java installed.
You have to add another step inside dockerfile:
RUN apk update && apk add openjdk(versionjdk)

Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/apt" (-1)

I am trying to install bowtie2, but I fail.
sudo apt install bowtie2
But I always got error messages:
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/apt" (-1)
I have been tried:
sudo ln -s /usr/bin/Java /Library/Java/JavaVirtualMachines/jdk9.0.4.jdk/Contents/Home/bin/apt
and
export JAVA_HOME='/usr/bin/Java'
But I am still unable to install my bowtie2 function.
Other backgrounds of this question:
Bowtie2 can be downloaded from https://www.java.com/zh-TW/download/
I store the unzipped file on the Desktop.
My Java files are at the below path:
/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/
My operating system version is macOS Mojave Version 10.14.6
Thanks in advance.

Google App Engine: JAVA command not recognized by Python in Flex environment with Docker (`java` command is not found from this Python process)

I deployed a Python project on Google App Engine. As the project has a dependency on Java, I used a Docker container configuring two environments: Python + Java.
However, when I make a call to my Python service in GAE it's getting "java command is not found from this Python process. Please ensure Java is installed and PATH is set for java" error.
During the build process of the Docker file I am able to access Java after installing it. But during API execution it is not recognized by Python.
The "app.yaml" file used:
runtime: custom
env: flex
entrypoint: gunicorn -w 4 -k uvicorn.workers.UvicornWorker src.main:app
Below are the the Docker file used in Deploy:
### 1. Get Linux
FROM alpine:3.7
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8
### 2. Get Java via the package manager
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies unzip \
&& apk add --no-cache curl \
&& apk add --no-cache openjdk8-jre
#### OPTIONAL : 4. SET JAVA_HOME environment variable, uncomment the line below if you need it
ENV JAVA_HOME="/usr/lib/jvm/java-1.8-openjdk"
RUN export JAVA_HOME
ENV PATH $PATH:$JAVA_HOME/bin
RUN export PATH
RUN find / -name "java"
RUN java -version
FROM python:3.7
EXPOSE 8080
ENV APP_HOME /src
WORKDIR /src
COPY requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt
COPY . /src
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8080"]
Here is a printout of the RUN java -version command during the deploy process:
RUN java -version command
Does anyone know why the error is happening even with Python and Java running on the same service on App Engine?
Are there any additional settings missing?
You are using two FROM in a Dockerfile, so you're effectively doing a multi-stage Docker build, but you are doing it wrong.
A multi-stage build should be something like this:
### 1. Get Linux
FROM alpine:3.7 as build
# here you install with apk and build your Java program
FROM python:3.7
EXPOSE 8080
...
# here you copy what you need from the previous Docker build, though
# since it was Java, which is not installed here anymore because it is
# a python image, you need to consider if you really need a multi-stage
# build
COPY --from=builder /src /src
Otherwise, just remove the second FROM python:3.7 and install it with apk.

Docker image for Debian : Access to the file or directory '/usr/local/openjdk-8/bin/java' is denied

While performing some Java related operation for Mendix on docker image "openjdk:8-jre" , I am getting an error: "System.UnauthorizedAccessException: Access to the file or directory '/usr/local/openjdk-8/bin/java' is denied."
Note: Command I am executing is not being executed manually, but I am using Gitlab for CICD for my project and one of the script is executing this Java related command.
A bit about Mendix : This is a platform I used for building my app. I am trying to build a deployable package on this docker image using following command.
mono /modeler/mxbuild.exe --output="Automation" --java-home =$JAVA_HOME --java-exe-path=$JAVA_HOME/bin/java Automation.mpr
I tried to execute following two commands before executing java command:
su
chmod 777 $JAVA_HOME/bin/java
chown -R root:root $JAVA_HOME
Not able to figure out why permission is getting denied .

apache ant Could not find or load main class org.apache.tools.ant.launch.Launcher

I'm trying to compile a tool which uses apache ant on linux
https://github.com/lindenb/jvarkit
When I tried to compile the tool , I get n error.
$ make vcffilterjs
this is what I get when I'm running the command
echo "Compiling htsjdk with ${JAVA_HOME} = /usr/lib/jvm/java/jre/"
Compiling htsjdk with /usr/lib/jvm/java/jre/ = /usr/lib/jvm/java/jre/
echo "Compiling htsjdk library for java. Requires apache ANT. If it fails here, it's a not a problem with jvarkit."
Compiling htsjdk library for java. Requires apache ANT. If it fails here, it's a not a problem with jvarkit.
echo "And ${JAVA_HOME}/bin/javac should be >=1.7"
And /usr/lib/jvm/java/jre//bin/javac should be >=1.7
(cd /home/jannahS/jvarkit/htsjdk-1.139 && ant )
Error: Could not find or load main class org.apache.tools.ant.launch.Launcher
make: *** [/home/jannahS/jvarkit/htsjdk-1.139/dist/htsjdk-1.139.jar] Error 1
I have installed apache ant and tried to set ANT_HOME following google instruction
export ANT_HOME=apache-ant-1.9.6
ANT_OPTS="-Xms256M -Xmx512M"
PATH=$PATH:$HOME/bin:$ANT_HOME/bin
export ANT_HOME ANT_OPTS PAT
I also have set JAVA_HOME
export JAVA_HOME=/usr/lib/jvm/jre-1.7.0
export PATH=$JAVA_HOME/jre/bin:$PATH
When I run
ant --execdebug
exec "/usr/lib/jvm/java/jre//bin/java" -Xmx256M -classpath "apache-ant- 1.9.6/lib/ant-launcher.jar" -Dant.home="apache-ant-1.9.6" -Dant.library.dir="apache-ant-1.9.6/lib" org.apache.tools.ant.launch.Launcher -cp ""
Buildfile: build.xml does not exist!
Build failed
I don't know what else to do to make things to work. I can't compile the tool that I want to use without apache ant
Use full path in ANT_HOME, eg:
export ANT_HOME=/usr/lib/apache-ant-1.9.6
It dependes where it is exactly located
Could not find or load main class org.apache.tools.ant.launch.Launcher
In mac this is due to some environment issue if you install the ant using brew command,
copy the lib folder from the ant and paste it into the bin folder
now run the command issue is resolved:-)
issue reason
ant is trying to get the bin/lib/ant-launcher.jar file from the invalid path
In Mac, after running brew install ant, I had to run brew link ant to fully link ant to system environment.
Running brew link --verbose --overwrite ant I get:
Linking /usr/local/Cellar/ant/1.10.5...
ln -s ../Cellar/ant/1.10.5/bin/ant ant
ln -s ../Cellar/ant/1.10.5/bin/antRun antRun
ln -s ../Cellar/ant/1.10.5/bin/antRun.pl antRun.pl
ln -s ../Cellar/ant/1.10.5/bin/complete-ant-cmd.pl complete-ant-cmd.pl
ln -s ../Cellar/ant/1.10.5/bin/runant.pl runant.pl
ln -s ../Cellar/ant/1.10.5/bin/runant.py runant.py
6 symlinks created
And when running "ant" with no params from command-line:
Buildfile: build.xml does not exist!
Build failed
Which is what I expect if testing outside the context of an existing ant project.
Run "which ant" >> to know if the ant_home set. If not please run below with your corresponding paths to set ant_home
export ANT_HOME =/ade_autofs/gd29_3rdparty/ANT_1.7.1_GENERIC.rdd/080925/ant
export PATH=/ade_autofs/gd29_3rdparty/ANT_1.7.1_GENERIC.rdd/080925/ant:${PATH}
Try ant build. It should work without any error.
"I agreed with full path issue for the above issue, getting the same exception while folder has access problem"
I have faced the same exception in Macbook. Checked all the configurations JAVA_HOME, ANT_HOME and org.apache.tools.ant.launch.Launcher file in Ant related jars. Finally, found the issue, due to an access problem of the apache-ant folder. I have no admin access, so I moved my setup to the desktop.
$ make vcffilterjs : Compiles OK, with any of these "Linux OS´s" :
Debian 8 Jessie, CentOS 7, Fedora 23, Ubuntu 15.10, PCLinuxOS 2015.
No "ANT_HOME" or "JAVA_HOME" settings required, by using the default installed 'ant' and openjdk.
? Which "Linux OS" are you using ?
antjvarkit

Categories

Resources