Where to find jni_md.h on CentOS OpenJDK 1.8 - java

I am building a java project using JNI and built using native-maven-plugin.
I am able to successfully compile and run my code on my local MacOS environment. However, this will need to run on a CentOS environment too and so I need to compile a .so library along my .jnilib .
I was thinking of copying jni_md.h from the CentOS environment to my local machine and provide the path to that header file to a CentOS compiler on my local machine.
However, I cannot find jni_md.h on the CentOS environment. I installed OpenJDK 1.8 using yum but I did not get an include/ folder in it.
Where can I find a linux version of jni_md.h to use on my local machine?
Bonus question: would my plan even work and is there a better way to do this?

This file should be located here
$JDK_HOME/include/linux
Question is, why do you need this one? You can't compile code that is supposed to run at CentOS at macOS - this will not work. And *.h files have nothing to do here. They are just headers.
Take a look here:
http://jnicookbook.owsiak.org/recipe-No-001/
You can find there a sample project that will compile just fine, at macOS and Linux.
All you have to do is to make sure to set JAVA_HOME such way it points to your JDK installation.
Have fun with JNI!

Related

Mac OS. No recognized OpenJDK

At first we are talking about MacOS Big Sur.
Until today I had the folder jdk-16.0.2.jdk with all its content in /Library/Java/JavaVirtualMachines which I downloaded from Oracle at a certain point in time.
It worked fine and java -version respondeds with the corresponding version and Netbeans worked fine along with Tomcat.
That was my java installation. Downloaded the .tar from Oracle and copy to that folder.
Today I am trying to migrate to openJDK so I did the same. I downloaded "openjdk-17.0.2_macos-aarch64_bin.tar" from java.net. Just the same procedure. Untar the files and copy to /Library/Java/JavaVirtualMachines (And moving the old Java to Desktop.
When I try % java -version I get:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
I resist a little to the idea of installing JAVA via homebrew (Which I use for other purposes) since I'd like to have the very same version in my dev environment (My Mac in this case) and in my production environment (Rocky Linux 8).
Any idea?
Thank you very much in advance.
If you have not yet updated your %JAVA_HOME% environment variable, that must be pointed to your new installation. Your installation path looks correct. Here is a thread about setting the environment variable: https://stackoverflow.com/a/65162351/1656012

Vscode extension error, java runtime could not be located on window subsystem for linux

I have installed the java runtime in the window subsystem for Linux (Ubuntu), and the Vscode is installed on the windows 10 system.
I did not install java runtime in windows 10 system. When I use vscode to edit java, it usually pop up a notice says the "java runtime could not be located".
I have point the vscode "java.home" to the java jdk directory of window subsystem linux file folder, which is C:\\Users\\Myusername\\AppData\\Local\\Packages\\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\\LocalState\\rootfs\\usr\\lib\\jvm\\. In the folder, it has:
java-8-openjdk-amd64 directory, and three files
.java-1.8.0-openjdk-amd64.jinfo,
default-java
java-1.8.0-openjdk-amd64.
But however, the vscode still pop out the notice that the java.home variable defined in VS Code settings does not point to a JDK.
Can anyone let me know how to set up the vs code properly so that it can locate the JDK file in the window subsystem for Linux (WSL)?
Thanks in advance.
It won´t work like this because you are trying to use a jdk builded for linux on windows.
It is the same as if you download the jdk for linux and try to execute on windows.
As for the solution, unfortunately there is no solution right now.
However you can call your java and javac directly on terminal using WSL
wsl javac
You can´t point the java_home using wsl.
Maybe in the future the guys from Microsoft can make the trick. I hope so.

Java Runtime Environment not found error

I've been working on Aptana Studio and some JRE required software for a bit of time now , but since yesterday something quite odd happened, as suddenly the software that requires it threw me an error No Java virtual machine was found . Last thing I did before that was restoring my system files permissions thought safe mode as I had some trouble with that , could this have anything to do with it ?
I've tried installing JRE once again , no results. However when I run
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
I do get the following
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
Aptana gives me the following error
No Java virtual machine
was found after searching the following locations:
/Applications/Aptana Studio 3/AptanaStudio3.app/Contents/MacOS/jre/bin/java
java in your current PATH
And other software such as Spine won't simply start.
My .bash_profile is the following :
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
PATH="/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/bin:${PAT$
export PATH
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home
The output of echo $PATHis the following
/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
The output of echo $JAVA_HOME is the following
/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home
And Java invocations on the terminal work.
Guidance will be highly appreciated.
After trying Peter's suggestion the problem persisted but now in another context : "/System/Library/Frameworks/JavaVM.framework" does not contain the JNI_CreateJavaVM symbol"
After struggling for many hours, and reading about people with the same issue opting to re-install the entire OS , decided to examine the issue from another perspective, the thing I first mentioned here that I believe went unnoticed was that I restored my permissions before this happening, so what I did was the following.
After reading a bunch of articles about Apple no longer providing Java support themselves but Oracle providing it, reasoned through it and realized that perhaps paths (Often called directories) from Apple's final Java release may have not been strictly the same as the new Oracle releases, so decided to wipe out all recent Oracle Java Runtime Environment that I found on /Library/Java/JavaVirtualMachines and delete the Java Applet Plugin from /Applications (Just search for it on your /Applications path) .
Installed Apple's last stable release from the following link.
Located where Apple located their Java releases : /System/Library/Frameworks/
My particular interest was the Java Runtime Environment , so I explored the JavaVM directory on /System/Library/Frameworks/
Found out that all Apple's JRE previous releases reside on a directory called Versions that is within /System/Library/Frameworks/JavaVM.framework directory, here's where I noticed something rare, for some reason at the moment I restored file permissions from my Disk Utility Application , this directory was made inaccessible (By not giving the root user permissions to access anything in itself).
Went to my terminal console and inside the JavaVM.framework directory modified the permissions to that directory to be accessible for all users by running the following command chmod -R 777 Versions.
After executing these actions I went straight to my JRE-Required software and attempted to open it , success!
Things to learn from the issue.
Oracle's Java JDK/JRE are located in different paths from Apple's. (If you are struggling with some other issue, verify your Java version to determine your Java installation directory)
Apple's disk utility application might define different permissions than expected for some files. (After restoring permissions verify that everything's working fine, if not this may be the cause of your problems.)
Looks like AptanaStudio (Eclisebased right?) assumes that you have a JRE inside the Aptana directory (/Applications/Aptana Studio 3/AptanaStudio3.app/Contents/MacOS/jre/bin/java)
I assume that there is nothing there. Simplest way would be to symlink your existing JRE installation to that directory:
ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/jre /Applications/Aptana\ Studio\ 3/AptanaStudio3.app/Contents/MacOS/jre
Or you could start Aptana from the terminal and specify the path to java with -vm:
./aptana -vm "/path/to/java/bin/directory"
Environment variables that must be available to GUI applications are a bit tricky in OsX (at least in my experience).
It is possible to set global PATH (and other variables) in /etc/launchd.conf, see for example here and /etc/paths.d see here.
Simple Solution
For Windows:
1.download the JAVA runtime environment x86(32bit) version else you will get an error with dll file from here http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
Extract the folder out of the .tar file you downloaded.
Rename the JRE folder to "jre"
Then paste it in to this directory
C:\Users\"User Name"\AppData\Roaming\Appcelerator\Aptana Studio
This worked for me
I uninstalled all my Java JREs and JDK for Windows 10. Then I downloaded Aptana again and let it install Java for me. I think JAVA 8 was my problem, but this worked and I can still install the other versions again.

ADT Bundle can't find Java

When I open adt-bundle-windows-x86_64-20131030 and click on the Eclipse.exe application to install it I get the message; A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java Virtual Machine was found after searching the following locations: C:\users\username\desktop\development\adt-bundle-windows-x86_64-20131030\eclipse\jre\bin\javaw.exe
javaw.exe is your current PATH.
I do have JDK, and JRE on this computer, I need them to view the emulator for my job. I have tried uninstalling and reinstalling Java with the same results. What can I do to fix this problem?
You will have to put Java in your classpath, so Eclipse knows where it can find Java. See here: http://docs.oracle.com/javase/tutorial/essential/environment/paths.html for info on how to do this.
install 32 bit version of jdk from oracle website
put the path of your java bin directory under Environment variables.
System->Advanced System Settings->Environment Variables->path
Open command prompt. use java and javac commands to know if you have successfully installed java and compiler.
if it doesn't help, this question has a lot of helpful answers
Eclipse - no Java (JRE) / (JDK) ... no virtual machine
From what you said:
"'java' is not recognized as an internal or external command, operable program or batch file"
Your java may not have been installed correctly, or, it was installed, but you did not set path to it correctly. It is not a problem with ADT, any of your programs that need Java will not be able to find it.

JNA native support (/com/sun/jna/linux-arm/libjnidispatch.so) not found in resource path

I have started to build a java service which incorporates JNA to load a native C/C++ lib and i want to run the java service on the Raspberry PI aka arm platform. I have successfully built a stable ground of the service and it runs on both Windows7 and linux-amd64/debian but.. on the RPI platform i get the above stated error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: JNA native support (/com/sun/jna/linux-arm/libjnidispatch.so) not found in resource path
On the RPI i have done the following:
* Installed both openjdk7 and java8 beta with arm hard float support.
* Installed libjna-java lib.
Following are set:
Java
root#pisces:/opt/TellstickReplay# java -version
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b36e)
Java HotSpot(TM) Client VM (build 25.0-b04, mixed mode)
root#pisces:/opt/TellstickReplay#
LD_LIBRARY_PATH
root#pisces:/opt/TellstickReplay# echo $LD_LIBRARY_PATH
/opt/lib/jna
CLASSPATH
root#pisces:/opt/TellstickReplay# echo $CLASSPATH
/usr/lib/jna
None of the settings seems to satisfy JAVA with JNA support. I have even tried to export both jna.jar and linux-arm.jar into the project in Eclipse and all together rebuild the jars into the exported jar still getting the same error. The exported jar has been tested successfully on both windows and linux so the jar file is working.
I have also tried to just use CLASSPATH in the Manifest in the jar file but with no success. I have also tried to explicitly load the libjnidispatch.so from the absolute path but JAVA then starts to complain that it cannot find the file to libjnidispatch.so even that the path is 100% correct.
So.. does anyone know HOW to correctly get JNA support on the Raspberry PI platform to work?? Please, im getting tremendously frustrated and soon giving up hope to fix this..
Where is libjnidispatch.so on your system? If it's not on your system, JNA will attempt to unpack it from jna.jar from the indicated resource path. If it's not there either, you'll get the UnsatisfiedLinkError.
It's recommended that you explicitly install libjnidispatch.so on your system where possible; the jna.jar bundling is mostly there to facilitate usage on the more common desktop platforms.
linux-arm.jar contains the most recent build of libjnidispatch.so, but only WebStart knows how to automatically load the native from a jar like that. If you unpack it into /opt/lib/jna (or elsewhere on LD_LIBRARY_PATH), you should avoid the link error.
I am re-compiling Apache Spark for RPI2 and I've spent a couple of days to fix the issue. Then I've found the easiest possible solution. All you need to have is a libjnidispatch.so link in your default JVM's native lib path.
sudo -s ln -s /usr/lib/arm-linux-gnueabihf/jni/libjnidispatch.so /usr/lib/jvm/default-java/jre/lib/arm/libjnidispatch.so
I packaged the new jna.jar (4.0) and it includes the linux-arm/libjnidispatch.so. The code I was trying to run now works.
I'd say its more of "glitch of configuration of the location for the "libjnidispatch.so" in the OS your using or that particular JRE systems internal folder/package/JNDI-structure, it may not be an identically laid out Debian or Java JRE.
I do the following:
sudo apt-get install libjna-java
get the installed jar /usr/share/java/jna.jar
Install jna.jar as a maven dependency
They worked to me...

Categories