Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is xlsx compatible with Java/16 ? #193

Closed
eylenth opened this issue Feb 3, 2022 · 8 comments
Closed

is xlsx compatible with Java/16 ? #193

eylenth opened this issue Feb 3, 2022 · 8 comments

Comments

@eylenth
Copy link

eylenth commented Feb 3, 2022

Hi

I'm trying to install xlsx with Java/16, but I'm getting the following error message:

Error: package or namespace load failed for xlsx:
 .onLoad failed in loadNamespace() for 'xlsx', details:
  call: .jnew("org/apache/poi/xssf/usermodel/XSSFWorkbook")
  error: java.lang.UnsatisfiedLinkError: $install_dir/Java/16.0.1/lib/libnio.so: $install_dir/Java/16.0.1/lib/libnio.so: undefined symbol: ipv4_available

is xlsx not compatible with Java/16 ?

@colearendt
Copy link
Owner

Interesting! I'm not sure! I will give this a check.

It's worth noting that you should be able to test the new version of embedded Java bits if you run:

remotes::install_github("colearendt/xlsx@bump-poi")

If this is indeed an "old version of the Apache POI library" issue, that should resolve it. However, I do not yet have all the kinks sorted out of that branch yet, so some functionality does not work.

I would be curious to hear what you find though!

@eylenth
Copy link
Author

eylenth commented Feb 4, 2022

I'm getting the following error message when I try to install the bump-poi version:

Installing package into ‘$install_dir/R-bundle-extra/4.0.3-foss-2020b-R-4.0.3’
(as ‘lib’ is unspecified)
* installing *source* package ‘xlsx’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error in .jcheck() : No running JVM detected. Maybe .jinit() would help.
Error: unable to load R code in package ‘xlsx’
Execution halted
ERROR: lazy loading failed for package ‘xlsx’
* removing $install_dir/R-bundle-extra/4.0.3-foss-2020b-R-4.0.3/xlsx’
Error: Failed to install 'xlsx' from GitHub:
  (converted from warning) installation of package ‘/tmp/Rtmp2hQPu2/file298fd4b653d78/xlsx_0.6.5.9100.tar.gz’ had non-zero exit status
> .jinit()
Error in .jinit() : could not find function ".jinit"
> .jcheck()
Error in .jcheck() : could not find function ".jcheck"

@colearendt
Copy link
Owner

Apologies for the late reply here. It sounds like some progress here though!

So the .jinit() function is in the rJava package. Maybe try:

rJava::.jInit()
# or
library(rJava)
.jinit()

@eylenth
Copy link
Author

eylenth commented Feb 16, 2022

I'm getting the following output:

> rJava::.jInit()
Error: '.jInit' is not an exported object from 'namespace:rJava'
> library(rJava)
> .jinit()
[1] 0

then I tried to install the xlsx bump-poi version again, but I'm getting the same error message

@colearendt
Copy link
Owner

(Sorry for the typo on the first .jinit(). Probably auto-correct got me). The "no running jvm detected" message? Maybe try this?

library(rJava)
.jinit()
.jcheck()
.jstrVal('hello')

Something weird is going on in your JVM, it seems like!

@eylenth
Copy link
Author

eylenth commented Feb 17, 2022

I'm getting the following output:

> library(rJava)
> .jinit()
> .jcheck()
> .jstrVal('hello')
[1] "hello"
> 

@colearendt
Copy link
Owner

Weeeird! So now that looks totally normal!! Ok, so I did a bit of testing and this looks like it works (even w/ the CRAN release of xlsx) in a vanilla container. Can you share the output of R CMD javareconf?:

# R CMD javareconf
Java interpreter : /opt/java/openjdk/bin/java
Java version     : 16.0.1
Java home path   : /opt/java/openjdk
Java compiler    : /opt/java/openjdk/bin/javac
Java headers gen.:
Java archive tool: /opt/java/openjdk/bin/jar

trying to compile and link a JNI program
detected JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
gcc -std=gnu99 -I"/opt/R/4.0.5/lib/R/include" -DNDEBUG -I/opt/java/openjdk/include -I/opt/java/openjdk/include/linux  -I/usr/local/include   -fpic  -g -O2  -c conftest.c -o conftest.o
gcc -std=gnu99 -shared -L/opt/R/4.0.5/lib/R/lib -L/usr/local/lib -o conftest.so conftest.o -L/opt/java/openjdk/lib/server -ljvm -L/opt/R/4.0.5/lib/R/lib -lR


JAVA_HOME        : /opt/java/openjdk
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
Updating Java configuration in /opt/R/4.0.5/lib/R
Done.

If you're on linux, you could also try:

find / -name 'libnio.so'
# /opt/java/openjdk/lib/libnio.so
ldd $( find / -name 'libnio.so' )
# ldd: warning: you do not have execution permission for `/opt/java/openjdk/lib/libnio.so'
#       linux-vdso.so.1 =>  (0x00007fff7a8d0000)
#       libjava.so => /opt/java/openjdk/lib/libjava.so (0x00007f9ef1f95000)
#       libnet.so => /opt/java/openjdk/lib/libnet.so (0x00007f9ef1d7f000)
#       libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f9ef1b63000)
#       libdl.so.2 => /lib64/libdl.so.2 (0x00007f9ef195f000)
#       libc.so.6 => /lib64/libc.so.6 (0x00007f9ef1591000)
#       /lib64/ld-linux-x86-64.so.2 (0x00007f9ef23cf000)
#       libjvm.so => not found
#       libjvm.so => not found

I'm wondering if there is something weird in your Java install (i.e. why that ipv4_address variable is missing)

The container I'm using, in case it is helpful:

Dockerfile

FROM adoptopenjdk/openjdk16:jdk-16.0.1_9-centos

ARG R_VERSION=4.0.5
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && \
  curl -O https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm && \
  yum install -y R-${R_VERSION}-1-1.x86_64.rpm && \
  /opt/R/${R_VERSION}/bin/R --version && \
  ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R && \
  ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript

Then:

docker build -f Dockerfile -t java-r .
docker run -it --rm java-r bash
R CMD javareconf
R -e 'install.packages("xlsx", repos = "https://cran.rstudio.com"); library(xlsx); xlsx::createWorkbook()'
# works fine

It's worth noting that Java weirdness is one reason that many people bail on xlsx (and rJava in general) 😞 R CMD javareconf is probably the most common fix, but it looks like your java install may have an issue.

@eylenth
Copy link
Author

eylenth commented Feb 17, 2022

R CMD javareconf didn't work as well..

Maybe I have to rebuild the whole R module with Java 16 (or 17)
But I will do that another time. that R module is quite large with a lot of dependencies which requires some time to rebuild

I will close this ticket for now, and I will create a new one if needed

@eylenth eylenth closed this as completed Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants