Centos OpenJDK1.8 install OpenJFX - java

I have a docker image where the building process roughly looks like this:
FROM centos:latest
...
RUN yum install -y java-1.8.0-openjdk-devel
...
I highly depend on the specific java version, so changing that is not an option.
Right now I need to add openjfx to this and make it work, yet all the available documentation seems to be not working on my centos/openjdk combination.
Downloading the zip file and adding it to my container and running the following commands as described here:
RUN export PATH_TO_FX=/var/lib/javafx/lib \
&& javac --module-path $PATH_TO_FX --add-modules=javafx.controls HelloFX.java \
&& java --module-path $PATH_TO_FX --add-modules=javafx.controls HelloFX
Failes, as:
javac: invalid flag: --module-path
What would be the correct way to add it to this docker image?

Related

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.

How to run JCMD without JDK on a docker container with openJDK installed

I need to run JCMD on prod to monitor my application, but unfortunately I can't have a proper JDK in place so I need to run it with a JRE. I can add some dependencies, but not the whole jdk.
I'm using openJDK 8.
Does anyone know how to do it?
There was one question already posted here (How to run jcmd without the JDK?), but the answer works for windows servers, not for linux OS in a docker container.
In my personal experience jcmd from newer version of Java works with the older versions.
You can exploit the multi-stage build feature and have jlink elegantly package for you the (strictly) necessary files, please refer to this Dockerfile:
FROM adoptopenjdk:11-jdk-hotspot
RUN ${JAVA_HOME}/bin/jlink --module-path jmods --add-modules jdk.jcmd --output /jcmd
FROM adoptopenjdk:8-jre-hotspot
COPY --from=0 /jcmd /jcmd
In case you prefer, I give you "an" answer for Java 8, using adoptopenjdk and multistage build
FROM adoptopenjdk:8-jdk-hotspot
RUN mkdir -p /jcmd && \
mkdir -p /jcmd/bin && \
mkdir -p /jcmd/lib && \
cp ${JAVA_HOME}/bin/jcmd /jcmd/bin/jcmd && \
cp -r ${JAVA_HOME}/lib/* /jcmd/lib
FROM adoptopenjdk:8-jre-hotspot
COPY --from=0 /jcmd ${JAVA_HOME}
in this case jcmd gets installed along the jre installation, in the same bin folder as java.
I tested both of them in both docker-desktop 20.10.7 and Mirantis (Docker Enterprise) 3.3.11.

Run gauge tests inside a docker container

I'm trying to Dockerize a Gauge test automation project so I can run specs inside a Docker container. The project is written in Java and Spring Boot.
I saw this tutorial in Gauge documentation.
This is the DockerFile in the tutorial:
FROM ubuntu
# Install Java.
RUN apt-get update && apt-get install -q -y \
openjdk-8-jdk \
apt-transport-https \
gnupg2 \
ca-certificates
# Install gauge
RUN apt-key adv --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys 023EDB0B && \
echo deb https://dl.bintray.com/gauge/gauge-deb stable main | tee -a /etc/apt/sources.list
RUN apt-get update && apt-get install gauge
# Install gauge plugins
RUN gauge install java && \
gauge install screenshot
ENV PATH=$HOME/.gauge:$PATH
As you see, there's no "ADD"/"COPY" there in the DokcerFile.
Is it just suggesting an alternative to install Gauge and the other packages on the host?
Any ideas on how to run the specs inside a Docker container?
Here is what I did to get the test running in the docker container.
I have a specs folder beside src in my project structure meaning the gauge tests will run using the JAR file but they're not part of the JAR file themselves.
--MyProject
----specs
----src
...
I used maven to run the test inside the container. That's why I preferred to build the project inside the container so I get the JAR file ready with the same version of maven I run the test with.
Here is the DockerFile. I developed a bash script to run the test. You may run the script with CMD or ENTRYPOINT:
FROM maven:3.6.1-jdk-8
# add any project resources needed
ADD env /home/e2e/env
ADD specs /home/e2e/specs
ADD src /home/e2e/src
ADD src/main/scripts/entrypoint.sh /home/e2e/
ADD pom.xml /home/e2e/
RUN ["chmod", "+x", "./home/e2e/entrypoint.sh"]
# Install Gauge, web browser and webdriver in your preferred way...
ENV PATH=$HOME/.gauge:$PATH
# I'm keeping the cntainer running. But it's all up to you.
CMD /home/e2e/entrypoint.sh && tail -f /dev/null
And then here is the simple entrypoint.sh script:
#!/bin/bash
cd /home/e2e/
mvn clean package
gauge --version
google-chrome --version
mvn -version
mvn gauge:execute -DspecsDir=specs/myTest.spec
Of course, you could just use a ready JAR instead of building it inside the container. Or you could build the JAR while creating the docker image.

gcc -x java on debian stretch

The Using the GNU Compiler Collection manual for gcc version 6.3.0 indicates support for the language option -x java on page 28 (page 42 of the pdf). Attempting this on debian stretch:
$ gcc -x java HelloWorld.java
gcc: error trying to exec 'ecj1': execvp: No such file or directory
Installing what seems to be the required package:
$ sudo apt-get install ecj1
Reading package lists... Done
...
Unpacking ecj1 (3.11.1-1) ...
Setting up ecj1 (3.11.1-1) ...
....
Reading state information... Done
However, I get the same error message when running gcc after this. In fact looking into /usr/bin, no executable ecj1 has been installed, and running apt-cache search ecj1 does not suggest any other package than the one I have installed.
$ gcc --version
gcc (Debian 6.3.0-11) 6.3.0 20170321
$ uname -a
Linux right 4.8.0-1-amd64 #1 SMP Debian 4.8.5-1 (2016-10-28) x86_64 GNU/Linux
Any suggestion as to what else I could try to get this running?
The GNU compiler for Java has to be installed:
$ apt-get install gcj-4.9 gcj-4-9-jdk
Use apt-file to search for packages containing ecj1 as a file. Note that apt-cache only searches for package names/descriptions matching the search.
After the installation I was able to run it using
$ gcj-4-9 HelloWorld.java
instead of gcc.
Even though gcj is a front-end to gcc, gcc didn't work for me and was complaining about the classpath not being set. To get gcc working, it would probably require a different, more complex command.
If you're compiling a class that contains a main method, use the --main option.
$ gcj-4-9 --main=HelloWorld HelloWorld.java

0 NATIVE_LIBRARY_NAME cannot be resolved or is not a field with Linux + Eclipse + Java

I get an error on Core.NATIVE_LIBRARY_NAME like so:
Stacktrace:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
NATIVE_LIBRARY_NAME cannot be resolved or is not a field
at MyVideoCap.main(MyVideoCap.java:7)
I had settled the NativLibrary path at the following location.
/home/.../OpenCV/opencv-2.4.5/build/lib
I had followed the instruction on https://www.openshift.com/blogs/day-12-opencv-face-detection-for-java-developers but it doesn't creates any opencv2.4.9.jar file I am working on ubuntu 12 and eclipse with opencv api suppoert.
so help me if you can to generating and building the jar file in the build directory in ubuntu. thanks in advance...
Here I found the full Installing progress of the OpenCV...
# install basic development environment
sudo apt-get install build-essential cmake pkg-config
# install opencv dependencies. ubuntu 13.04 ships with opencv which is close enough to 2.4.6 to pull in most of the needed dependencies.
sudo apt-get build-dep libopencv-dev
# additional dependencies for java support
sudo apt-get install default-jdk ant
# compile opencv
tar xzvf opencv-2.4.6.1.tar.gz
cd opencv-2.4.6.1
mkdir build; cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON ..
make
sudo make install
And in last don't forget to set Native library path to the
/home/.../opencv-2.4.6.1/build/lib
Thats it...

Categories

Resources