Running an android binary on Ubuntu (libc.so: invalid ELF header) - java

I am trying to run a java application on spring boot running on ubuntu. My application has a dependency on a jar file that loads two binaries:
"libc++_shared.so" and "libsigx.so"
I extracted the jar file and so files from an aar file that is created as a dependency for android, but I would really like to use this on my server. I was able to write the java code I need without an issue after I added the jar file as dependency to my spring boot application.
However, when these binaries are loaded(e.g System.loadLibrary("c++_shared")) in Java, I got an exception saying that libc.so is not found. Apparently, I needed to install some other binaries, so I installed the necessary binaries to my docker container by using
sudo apt-get install build-essential
Now I have all the binaries needed(libc.so, libm.so etc), but now when I run my jar file I get invalid ELF header exception:
Caused by: java.lang.UnsatisfiedLinkError: /usr/java/packages/lib/libc++_shared.so: /lib/x86_64-linux-gnu/libc.so: invalid ELF header
When I run the readelf -h command on so files:
The c++ so file has OS/ABI: UNIX - System V header, while libc.so has OS/ABI: UNIX - GNU. Looks like binaries are not compatible and I am trying to find to solve this.
Couple of questions that come to mind are:
Is it possible to get these binaries to run in a compatible way with some commands? Maybe convert binary for system v to gnu somehow?
Is it possible to find "libc++_shared.so" and "libsigx.so" created for OS/ABI: UNIX - GNU
I am open to any workaround to get these libraries running together. Thanks

Related

How do I use a library on a exported runnable jar?

I've got a java script that uses OpenCV 4.6.0 to modify some pics. I use Eclipse to edit the java project. I downloaded the OpenCV library (a opencv_460.jar file) which is used inside Eclipse. When I run the code, it works just fine. So I export the java project as a runnable jar.
The thing is that I want to use the jar on a different machine (ubuntu 18.04). When I run java -jar TheExportedJar.jar, I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java460 in java.library.path: /usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
I installed OpenCV 4.6.0 on the machine using CMake
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.6.0.zip
unzip opencv.zip
mkdir opencv-4.6.0/build
cd opencv-4.6.0/build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PKGCONFIG=ON ..
make -j$(nproc)
sudo make install
The version is ok, everything looks fine, except it doesn't actually get installed. Things that should exist, like alternative path /usr/local/lib/pkgconfig/opencv4.pc, don't actually exist
How does java work? Why can Eclipse use a jar as a library, but I can't once the project is packed? Is there a way to skip the installation process (as every type of install I've tried was just a waste of time) and import a jar from a specified path as a library inside the java code?
What other solutions could there be?

How to build jar Library for openconnect client? (no configure file)

I want to build a jar-library for the openconnect client. But I couldn't find the configure-file there is only a configure.ac file that seems to include the code for the configure file. The content of the readme-file couldn't help me:
Description:
This directory contains a JNI interface layer for libopenconnect, and a
demo program to show how it can be used.
Build instructions:
From the top level, run:
./configure --with-java
make
cd java
ant
sudo java -Djava.library.path=../.libs -jar dist/example.jar <server_ip>
If ocproxy[1] is installed somewhere in your $PATH, this can be run as a
non-root user and it should be pingable from across the VPN.
Test/demo code is in src/com/example/
OpenConnect wrapper library is in src/org/infradead/libopenconnect/
[1] http://repo.or.cz/w/ocproxy.git
ant worked but ./configure didn't work.
Any suggestions?

Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory

I have installed ghostscript of 64 bit on my 64 bit linux machine. I am using ghost4j-0.5.0.jar to convert pdf files to tiff files. I have written a java program which will convert pdf files to tiff files. This is working perfectly fine on Windows but when i thought of moving this to linux machine i am getting the below error.
"Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory"
I checked lib folder and could not find libgs.so file in the lib folder. I am not sure where to get that file.
Can anyone please help me on this ?
I feel a little guilty posting this here since it is probably better served on ServerFault or one of the Linux boards and the question is over 6 months old but I had been banging my head against the wall all day and finally have found a solution to this problem and I figured someone else might benefit from this down the road.
Systems: Windows 7 and CentOS 6.5
Using: Ghostscript 9.14
A little backstory:
Like the OP I had been running a ghostscript program on Windows to convert PDFs to a series of images. This worked fine until I needed to switch over to Linux and run the program and about 5% of the PDFs I needed to convert came up with error cannot decode code stream. I realized that I was using a newer version of ghostscript on Windows. (9.14 on Windows compared to 8.70 on CentOS due to installing through yum).
I removed the old version with yum remove ghostscript. Next, I found the easiest way to install the newest version of Ghostscript is download from here and compile. Since I removed the previous version of ghostscript with yum I had to update the link in usr/bin to point to usr/local/bin/gs with ln -s /usr/local/bin/gs /usr/bin/gs. With everything in place, so I thought, I attempted to run my program and then bam, error!
Solving the problem:
So now I was getting the error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory
I came across a post here that said to get the necessary libgs.so I needed to go back and rebuild the source as a shared library with the command make so. I did so and then I took the libgs.so.9.14 file under sobin directory in the ghostscript folder and copied it to /usr/lib. Under that directory I made a symbolic link to libgs.so using the command ln -s /usr/lib/libgs.so.9.14 /usr/lib/libgs.so.
Once that was done I needed to update my ld_library_path but found when I did so the change wasn't global so I found a Unix & Linux post on how to set the global lib path. Basically to do so you need to go to add a .conf file in /etc/ld.so.conf.d/ with the path to the file. I did so using vi /etc/ld.so.conf.d/libgs.conf and added /usr/lib/libgs.so to the file. Lastly I ran ldconfig so save the changes.
TLDR:
Download the latest version of Ghostscript from source: wget http://downloads.ghostscript.com/public/ghostscript-9.14.tar.gz
Unpack the tar: tar -xzf ghostscript-9.14.tar.gz
cd ghostscript-9.14
./configure
make <-- You might be able to skip and go to make so, I did it in this order so I will leave it like this.
make install
make so
If you removed a previous version with yum ln -s /usr/local/bin/gs /usr/bin/gs
cp ghostscript-9.14/sobin/libgs.so.9.14 /usr/lib
ln -s /usr/lib/libgs.so.9.14 /usr/lib/libgs.so
vi /etc/ld.so.conf.d/libgs.conf
In the new libgs.conf file: /usr/lib/libgs.so and save with esc, :, wq.
ldconfig and done.
Run your conversion program.
Hopefully this helped and wasn't too confusing. I'm not a linux expert (yet) so I may be doing a little more work than necessary with the above commands but I wanted to be thorough.
I just had this issue on a linux VM. I was able to solve it by installing ghostscript on the system. I just used the command:
sudo yum install ghostscript
Hope that helps!
make soinstall will create required libs along with executables as mentioned in https://www.ghostscript.com/doc/current/Install.htm#Shared_object

java.lang.RuntimeException: Registry initialization file not found

When I work with JAI from the Eclipse (all the classes specified)
it works very fine, but when I bundle everything in a jar and make a shell script file from that and try to run that script I have a problem with javax.media.jai.OperationRegistry
looking for a initialization file.
Has anyone else seen this problem?
Exception:
java.lang.RuntimeException: Registry initialization file not found.
at
javax.media.jai.OperationRegistry.initializeRegistry(OperationRegistry.java:365)
at javax.media.jai.JAI.(JAI.java:566)
There is something on this page but I was not able to understand.
Any Help?
So the problem is that the JAI jar exported with the Java application do not work on the Linux. We have to explicitly install JAI on the Linux machine for the installed Java application to use.
The one solution that we found out is we exported our Java Application into a jar file and created a installation script, which when run on the Linux machine install the JAI first and after that it install our application.
So this is a one time installation process while installing the application on any fresh Linux machine.

Having issues installing Hibernate3 on Debian Server

I am attempting to install Hibernate3 onto my linux server but I'm having a hard time figuring out what to do to get it to work. I have tried the following:
copy required jars into a folder and called the folder via "java -classpath etc." and got
java -classpath /home/mcmaster/javalibs/* -jar craftbukkit.jar
Error: Could not find or load main class .home.mcmaster.javalibs.dom4j-1.6.1.jar
load the java command while calling only the core hibernate which resulted in normal class not found error
on a whim installed to system java lib location with no affect
used apt-get to install libhibernate3-java with no change
I have attempted to export $CLASSPATH=~/javalibs which has all the required jars
I'm literally pulling my hair out as an intermediate java user trying to learn some more advanced things(to me).
Here's the error I'm getting when trying to call the Session Class:
Caused by: java.lang.ClassNotFoundException: org.hibernate.Session
Looks like you forgot the quotation marks. Try
java -classpath '.:/home/mcmaster/javalibs/*' -jar craftbukkit.jar (as seen on wikipedia).
EDIT: I am guessing that craftbukkit.jar is executable.

Categories

Resources