DRMAA and the shared.library.path - java

I try to use the sun grid engine with the DRMAA api by following the tutorial found at: http://gridscheduler.sourceforge.net/howto/drmaa_java.html. For this I need to load the c library located in /srv/sge/lib/lx24-amd64/drmaa.so. Now I execute my command with this code: java -jar scriptName.jar -Dshared.library.path=/srv/sge/lib/lx24-amd64/ as described in https://blogs.oracle.com/templedf/entry/drmaa_and_the_shared_library. But still I get the this exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no drmaa in
java.library.path
This exception is thrown when trying to retrieve the session:
session = SessionFactory.getFactory().getSession();
OS is linux 64 bit, java is 64 bit and SGE is 64 bit, so this is all compatible.
Does anyone know what is going wrong?

You will want to change shared.library.path to java.library.path (I believe that is a mistake in the blog post you referenced.
Also, place the -D switch before the -jar switch in your command, otherwise it is interpreted as an argument to the main function in the jar file rather than an argument to the JVM.
So, your example command should now look like this:
java -Djava.library.path=/srv/sge/lib/lx24-amd64/ -jar scriptName.jar

The case seems to be that in some distributions the libdrmaa.so has a library version number libdrmaa.so.1.0 while the libdrmaa.so without version number is missing. The drmaa.jar seems to just look for the one without. You can check which of the libdrmaa.so libraries are available in your system using
# ldconfig -p | grep libdrmaa
Which (in my case) either says
libdrmaa.so.1.0 (libc6,x86-64) => /lib64/libdrmaa.so.1.0
or
libdrmaa.so.1.0 (libc6,x86-64) => /lib64/libdrmaa.so.1.0
libdrmaa.so (libc6,x86-64) => /lib64/libdrmaa.so
The second case is the good one!
For Fedora distributions I reported this as a bug and it seems that they fix it in F18 and F19 soon. https://bugzilla.redhat.com/show_bug.cgi?id=671880
It is an easy fix in Fedora to simply install the package "gridengine-devel" where this soft-link is included.
If the libdrmaa.so without version number is not there and you are on another distribution, you can fix it manually as system administrator by typing
# cd /usr/lib64
# sudo ln -sf libdrmaa.so.1.0 libdrmaa.so
# sudo ldconfig

None of the previous answers worked for me. I've managed to solve this problem defining in my environment the following variable
export LD_LIBRARY_PATH=<path to the drmaa lib>

Related

Set PATH and JAVA_HOME in Fedora 25

Please excuse what appears to be a question answered before, but if I read 10 different posts I find 20 different responses.
I just installed Fedora 25. I am going to be learning Java development and need to set up my environment. I will be using openjdk and have installed java-1.8.0-openjdk-devel. I will also be using Maven.
Now I need to set my $PATH and $JAVA_HOME variables.
I tried the answer found here (Fedora OpenJDK Set JAVA_HOME)
but after adding to my .bashrc
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
and then testing, I get what appears to me to be the wrong answer because I do not think there should be a /jre/ on the end
> echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-1.b14.fc25.x86_64/jre/
So can I please ask what I should set JAVA_HOME to so that I do not need to update it with every openjdk update?
After that I think PATH is just
export PATH=$JAVA_HOME/bin:$PATH
this seems like such a straightforward thing to do yet it seems to me there is much confusion. thx
PS
also, is .bashrc even the correct place? because I see here (https://askubuntu.com/questions/175514/how-to-set-java-home-for-java) that /etc/environment would be more appropriate) thx
I suggest create an alias command, modifying bashrc and set JAVA_HOME
into bash_profile, this:
Create command in the bashrc:
alias set-java='sudo alternatives --config java;export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::");source ~/.bash_profile'
Save and execute: source ~/.bashrc
Create generic JAVA_HOME in bash_profile:
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
PATH=$JAVA_HOME/bin:$PATH
Execute the alias command
Set JAVA_HOME :
echo "JAVA_HOME=/etc/alternatives/jre" >> ~/.profile
source ~/.profile
echo $JAVA_HOME
I put the following in ~/.profile, not ~/.bashrc and I think it's the same on Fedora (I used CentOS at work and do the same):
export JDK_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JAVA_HOME=$JDK_HOME/jre
I have to either sign out or reboot after changing .profile.
On Ubuntu, java only changed from 7 to 8 a few years ago. I don't know why Fedora would want to put an exact version number on the java folder. You might complain?
If Java moves around too much for you on Fedora, use a symlink. The symlink takes affect right away, without logging out or rebooting. On my laptop, I encrypt my home folder, so for extra speed, I put most third party tools in a /tools/ folder and give myself account access to it (sudo chown -R myself.myself /tools/ where myself is my user ID). That's where I put my maven install. Tomcat uses a different directory name for each release, so I make a symlink like so:
cd /tools
ln -s apache-tomcat-8.0.38 latest-tomcat
Then in ~/.profile (CATALINA means TOMCAT in this example - don't ask me why):
# My un-encrypted Tools folder
export TOOLS=/tools
# Tomcat
export CATALINA_HOME=$TOOLS/latest-tomcat
# Maven
export M2_HOME=$TOOLS/apache-maven-3.3.9/
export M2="$M2_HOME"bin
export PATH=$PATH:$M2
When I upgrade tomcat:
cd /tools
rm -f latest-tomcat
ln -s apache-tomcat-8.0.39 latest-tomcat
You can use the same technique to make a /usr/lib/jvm/latest-java. In fact, if you install Oracle Java (not necessarily recommended), it does exactly that, for this reason.
Yes, what you said about the path looks correct to me. I don't put java in my path, preferring to use $JDK_HOME, $JAVA_HOME, or just calling maven. Part of that is for security. Part of it is to feel like I always know which version of Java I'm using.
P.S. To me, the ln -s syntax always looks as if the arguments are reversed. The actual folder name goes first, followed by your desired alias/link.
OpenJDK bundled with Fedora dosen't work for me. For example IntelliJ can't use this version. In my opinion, best option is to install Oracle JDK RPM from Oracle.
JDK location:
/usr/java/latest/
To manipilate JRE use command below:
sudo alternatives --config java
So far, this gets Android Studio running using the Fedora provided OpenJDK and respects the distribution provided materials without a bunch of otherwise unmanaged symlinking:
vim ~/.bash_profile
Add the following, or replace any existing examples that look similar to it:
export JAVA_HOME=$(readlink -f /usr/bin/java | cut -d/ -f1-6)
The command basically asks for the physical path that the symlink /usr/bin/java points to (configured by alternatives in Fedora), and then says "take the first 6 fields given to you by splitting on the / character."
Note that your $PATH will already be set up correctly for use with the Fedora provided OpenJDK.
In practice, this ends up looking like:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-8.fc28.x86_64/jre
This assumes you have at least one of the OpenJDK packages Fedora ships. 25 probably only shipped 1.8, 28 ships 1.8, 10.0.2, and 11.0.1. (if you're reading this and still using 25, it's probably time to upgrade.)
Install one of the java-*-openjdk-headless packages available to you (or one of the Oracle provided ones), and configure which one to use using:
sudo alternatives --config java
The default on my Fedora 28 install was to use OpenJDK 1.8.
Sadly I don't have Fedora available for me, so I can't investigate how Java is usually installed, but why you don't try to replace /usr/bin/java in your expression with something like /usr/bin/javac? The actual path to javac link you can get with
which javac
And read the real path with readlink. Obviously, it works if JDK is installed (not JRE).
About updating, most of Linux distros create a symbolic link like /usr/lib/jvm which is set to the correct directory and update in case of new version. For me better solution it to put this path in your bashrc.
And yes, bashrc is usually enough if you don't need JAVA_HOME to be visible to other OS users.
Maybe adding a tr could work? export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::" | tr -d "/jre/") ?
Also, setting it in your env var will make the var independent from the sh your using. That's a great way to store It.

How to install java locally - no root - on linux, if possible?

I need java 1.7 and server has only got 1.6. I have no root privileges. I tried to google out something but it seems like nobody was doing it. Can I somehow compile it or get ready binaries so I could put those into my PATH. Could you help? System is Redhat.
It is quite easy...
Download the JDK as a tarball from Oracle (a simple google search will yield the link).
Unzip it somewhere in your $HOME (for instance, $HOME/jdk).
Set JAVA_HOME to the path of the root JDK install; then prepend $JAVA_HOME/bin to your PATH.
And off you go.
Here I have a particular setting insofar as I run three different major versions of the JDK: 6, 7, 8. For instance, here is my source file for setting the current shell to use Java 8:
$ cat ~/.jdk/8
export JAVA_HOME=/opt/sunjdk/1.8/current
export PATH="$JAVA_HOME/bin:$PATH"
And in /opt/sunjdk/1.8 (given that /opt/sunjdk is writable by my user hence I don't need to be root):
$ ls -l /opt/sunjdk/1.8/* -d
lrwxrwxrwx 1 fge fge 11 Oct 30 10:09 /opt/sunjdk/1.8/current -> jdk1.8.0_25
drwxr-xr-x 1 fge fge 274 Mar 18 2014 /opt/sunjdk/1.8/jdk1.8.0_05
drwxr-xr-x 1 fge fge 274 Sep 18 02:44 /opt/sunjdk/1.8/jdk1.8.0_25
(and yes, I was root to begin with so as to grant write permissions for /opt/sunjdk to "my" user; if you have no such liberty, just create another directory in your home)
Oracle offers JRE and JDK also as *.tar.gz for Linux. I usually had success just downloading such a package, untarring/unzipping it (tar -xzvf jdk-8u25.tar.gz) and then running it, using the absolute path.
I was able to accomplish this using conda.
Conda is an open-source package-manager by Anaconda, that according to the website:
You do not need administrative or root permissions to install Anaconda if you select a user-writable install location.
You can search the package repo from a browser at anaconda.org or command line, for example here are the results for JDK.
For Linux, you would download this installer. Here is a command line that will start the installer for convenience:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && bash Miniconda3-latest-Linux-x86_64.sh
Once conda is installed, you can install packages. For example, to install the JetBrains Runtime OpenJDK build:
conda install -c anaconda openjdk
Other builds may be available from other channels in the repository.
The instructions above should give a working install, but the Getting started guide is a good place to get started. Conda uses the concept of environments to help manage versions and paths in a fairly simple and straightforward manner.
I hope this helps someone.
export JAVA_HOME=/opt/sunjdk/1.8/current
export PATH="$JAVA_HOME/bin:$PATH"
For me this option only worked when I changed linux to use bash instead ksh. I don't know if this is some kind of configuration in my company, but when I tried to run via ksh using "set" command instead "export" to define path, It was set correctly with the path of my new Java installation, but when I typed which java the old version was showed. But, when I executed bash, and typed the "export", it worked. So, if someone have the same problem to configure it using set command, try to use bash with export command. I am using Redhat 6.2.

JNA UnsatisfiedLinkError - works when I set java.library.path to a bogus value

Using JNA 4.0.0, on Linux, I am trying to load a native library (libmean.so), which is in the lib subdirectory (the library is just a trivial example that calculates the mean of two numbers).
I run the following code (within Eclipse), with -Djna.library.path=lib set in the run configuration.
import com.sun.jna.Library;
import com.sun.jna.Native;
public class Mean {
public interface MeanLib extends Library {
MeanLib INSTANCE = (MeanLib) Native.loadLibrary("mean", MeanLib.class);
double mean(double a, double b);
}
public static void main(String[] args) {
double result = MeanLib.INSTANCE.mean(1.0, 3.0);
System.out.println(result);
}
}
But this fails with the following exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't obtain updateLastError method for class com.sun.jna.Native
at com.sun.jna.Native.initIDs(Native Method)
at com.sun.jna.Native.<clinit>(Native.java:139)
at com.sun.jna.examples.Mean$MeanLib.<clinit>(Mean.java:64)
at com.sun.jna.examples.Mean.main(Mean.java:72)
Through trial-and-error, I have discovered that the code starts working if I also set java.library.path.
However, it works regardless of the value of this property. For example, I can set -Djava.library.path=xxxxxxx and it continues to work. An empty value also works.
What is going on?
The root problem is that there is an older version of JNA installed on the system:
$ dpkg -l | grep -i jna
ii libjna-java 3.2.7-4 Dynamic access of native libraries from Java without JNI
JNA starts up by trying to load its bootstrap native library. It searches for this in various places, as described in the documentation.
The problem is fixed by using the -Djna.nosys=true flag, which forces JNA to load the native library from your jna.jar, not from the system.
Setting the java.library.path to a nonsense value has a similar side-effect - it overwrites the normal java.library.path, preventing the system version of JNA from being loaded, and falling back on the version from your local jna.jar.
The debug setting -Djna.debug_load=true is also useful for diagnosing JNA problems.
$ dpkg -l | grep -i jna
try this command and if u getting this output
ii libjna-java 3.2.7-4 Dynamic access of native libraries from Java without JNI
or any other output then this u need to remove then that jna from the system because if program itself have jna jar with that then there is no need of system jna for the same. so do something like this.
sudo apt-get autoremove libjna-java
and try for restart that application again. it will run and it is not running then try to install new version of libwebkit-gtk.
hope this will help. this helped me.
I got this error when I'd installed Netbeans 7 via apt-get which pulled in libjna-java (3.2.7-4).
Since Netbeans 7 is old, I installed version 8 via their shell installer after removing the debian packages. Be sure and autoremove to get rid of libjna.

64 Bit Java Path in Cygwin

Ok, so this is actually quite a long story, but i'll try and keep it pretty short. So I'm trying to get the WebOS SDK working on Windows using Cygwin. Well, it wasn't working. It kept complaining that i was using a 32 bit version of java instead of 64 bit. the explenation for that problem is pretty easy to figure out. my PATH variable was set wrong and was pointing to my 32 bit installation of Java. Simple solution YOU'D THINK. apparantly not. for some reason, despite my best efforts, i cannot get the 64 bit version of java written into the PATH variable. The problem:
Cygwin doesn't like spaces in the Path variable, even though the path variable is littered with spaces, it won't accept it when i add my own space. After a lot of googling, i've found multiple accurances of this problem, and multiple solutions. but none of them seem to work. i always get exactly the same error:
bash: /usr/local/bin:/usr/bin:/cygdrive/c/Program: No such file or directory
The error is pretty self explanetary, basically its not reading anything past the first space, and i have no such directory as C:/Program so it spits out an error, my question is how do i get it to except a space, because changing the name of the directory is not an option, too many things depend on it. heres what i've tried so far:
$PATH=$PATH:C:\PROGRA~1\Java\jre6
$PATH=$PATH:"'pwd'" (while in java directory)
$PATH=$PATH:/cygdrive/c/Program Files/Java/jre6/bin (hay, i had to try)
$PATH=$PATH:/cygdrive/c/"Program Files"/Java/jre6/bin
$PATH=$PATH:/cygdrive/c/Program\ Files/Java/jre6/bin (escape character was rumored to work
$PATH=$PATH:'/cygdrive/c/Program Files/Java/jre6/bin'
$PATH=$PATH:"`/cygdrive/c/Program Files/Java/jre6/bin`"
and i think that was it, if anyone knows how to actually do it properly (or improperly but working for all i care) it would be greatly appreciated
Thanks
--
Chris
You also have the option of using the cygpath tool to help. Cygpath can be used to convert from a Window's path to a Unix path, but that doesn't directly handle spaces, so you need to do a two step process, first eliminate the spaces by converting to a DOS (short) path name, then convert to a Unix style path:
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files\Java\jre6\bin")):${PATH}
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files (x86)\HP webOS\PDK\bin")):${PATH}
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files (x86)\HP webOS\SDK\bin")):${PATH}
PATH=$(cygpath -u $(cygpath -m -s "C:\Program Files (x86)\HP webOS\SDK\bin\novacom")):${PATH}
The end result will be something like (short names may differ slightly):
/cygdrive/c/PROGRA~3/HPWEBO~1/SDK/bin/novacom:/cygdrive/c/PROGRA~3/HPWEBO~1/SDK/bin:/cygdrive/c/PROGRA~3/HPWEBO~1/PDK/bin:/cygdrive/c/PROGRA~1/Java/jre6/bin:....other path elements....
One thing to keep in mind when using this, cygpath generates an error if the provided path actually does not exist because it can not create the short path for a non-existent path.
What is nice about this approach is that if you set Windows environment variables (like for example JAVA_HOME) then you can use that environment variable in the convert operation inside the .bash_profile, since all Windows environment variables are visible when the profile is being loaded. So if you had in the Windows environment
JAVA_HOME=C:\Program Files\Java\jre
then the cygpath command can be
$(cygpath -u $(cygpath -m -s "${JAVA_HOME}\bin"))
which means you only ever need to update via the Windows settings if the java install changes.
In .bash_profile:
PATH=/cygdrive/c/Program\ Files/Java/jre6/bin/:${PATH}
PATH=${PATH}:/cygdrive/c/Program\ Files\ \(x86\)/HP\ webOS/PDK/bin
PATH=${PATH}:/cygdrive/c/Program\ Files\ \(x86\)/HP\ webOS/SDK/bin
PATH=${PATH}:/cygdrive/c/Program\ Files\ \(x86\)/HP\ webOS/SDK/bin/novacom
Adds the paths to your .bash_profile and both java and the webOS SDK tools should be available.

How to setup java on freebsd?

I have both Java JRE and Java JDK on a FreeBSD 7.2 box (running PFSense) from http://www.freebsdfoundation.org/downloads/java.shtml
find / -name gives me output like:
/usr/local/diablo-jre1.6.0/bin/java
/usr/local/diablo-jdk1.6.0/bin/java
/usr/local/diablo-jdk1.6.0/jre/bin/java
so I make a link to /usr/local/bin like so:
ln /usr/local/diablo-jre1.6.0/bin/java /usr/local/bin/java
and now I get
# rehash
# java
Error: could not find libjava.so
Error: could not find Java 2 Runtime Environment.
SOOOOOO, I'm wondering if there is some tool I can use to turn on a particular java vm similar to Ubuntus' /etc/jvm?
The /usr/local/diablo-jre1.6.0/bin/java application probably locates libjava.so relative to the location of the java application itself. By creating a hard link to java and executing it via that hard link, you've probably broken that mechanism.
Suggestions:
Put /usr/local/diablo-jre1.6.0/bin on your search path.
Create an alias for java instead of a link.
Replace the hard link with a symbolic link; i.e. use ln -s to create it.
The FreeBSD packages should have installed a wrapper-script in /usr/local/bin/java that knows about the different installed JVMs, and their JAVA_HOMEs etc. Did you by chance accidentally download the tarball instead of the package?
What does pkg_info | grep jdk yield?
If this is in a jail, you may need to move /proc temporarily so it doesn't try to use it to find out where the Java libraries are. Got bitten by this one!

Categories

Resources