Java Screen with Custom JAVA_HOME and LD_LIBRARY_PATH - java

I have a appilcation that needs Java 32bit on my Debian 64bit server. Is running fine now with this in the .profile or in the SH file.
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_25/
export LD_LIBRARY_PATH=.:$JAVA_HOME/jre/lib/i386/server:$JAVA_HOME/jre/lib/i386/client:/usr/local/lib
However, when I to start it over screen it simply don't load the Java path and the LD lib path.
Anyone has a idea how to solve this problem?

Please, give me the results the next commands in your console
java -version
and
echo $JAVA_HOME
echo $LD_LIBRARY_PATH
Do you have this in you environments variables?
env | grep JAVA
In my case I have this
user:$ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
user:$ echo $JAVA_HOME
/opt/jdk/jdk1.8.0_25
user:$ env | grep JAVA
JAVA_HOME=/opt/jdk/jdk1.8.0_25

Related

Setting $JAVA_HOME as opc, not accessible as oracle

I am currently with installing and integrating a couple of software on Linux, and I'm very new to Linux. One of the software refuses to run and instructs me to properly set $JAVA_HOME. But I have set $JAVA_HOME! However, when I check the $JAVA_HOME and java -version tests to see if I have done it correctly, it only produces the correct answer when I'm logged in as opc. The permissions of the software I am trying to install is oracle. Do I need to set $JAVA_HOME again when I'm logged in as oracle? And why?
[opc#mydir ~]$ $JAVA_HOME
-bash: /u01/jdk-11.0.3/: Is a directory
[opc#mydir ~]$ java -version
java version "11.0.3" 2019-04-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.3+12-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.3+12-LTS, mixed mode)
[opc#mydir ~]$ sudo su oracle
[oracle#mydir opc]$ $JAVA_HOME
[oracle#mydir opc]$ java -version
bash: java: command not found
Environment variables (such as $JAVA_HOME) are set per process. For shells, you'd usually have some initialization script (like .bashrc) that sets all the relevant variables for the current session. You should copy the initialization of $JAVA_HOME you have in the opc user to the oracle user too.

Unable to find java executable. Check JAVA_HOME ... while starting Cassandra

Running Cassandra
$ apache-cassandra-3.11.1/bin/cassandra -f -R
Unable to find java executable. Check JAVA_HOME and PATH environment variables.
Java Settings are
java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (Zulu 8.20.0.5-linux64) (build 1.8.0_121-b15)
OpenJDK 64-Bit Server VM (Zulu 8.20.0.5-linux64) (build 25.121-b15, mixed mode)
whereis java
java: /usr/bin/java /usr/lib/java /etc/java /usr/share/java /data/ytbigdata/anaconda3/bin/java
which java
~/anaconda3/bin/java
~/.bash_profile setting
export JAVA_HOME=/data/ytbigdata/anaconda3/bin/java
export PATH=$JAVA_HOME/bin:$PATH
The Cassandra documentation says "On the Cassandra nodes where the agents are installed, create the file /etc/default/datastax-agent and set the environment variables for JAVA_HOME and any other custom environment variables that the agent might need." https://docs.datastax.com/en/opscenter/6.1/opsc/install/opscCustomVariables_t.html

How do you switch back and forth between Java 1.7 and Java 1.8 on Mac OS X?

I am trying to have both versions of Java installed on my machine and move to and fro between them. What is the best way to do that?
If you are moving to Java 8 and still want to run Java 7 the following script might help you.
Step-by-step guide
This script that enables you to switch between Java 1.7 and Java 1.8.
Insert the below code block in your .bashrc or .bash_profile scripts in your home directory.
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $#`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
#set default jdk version
setjdk 1.7.0_60
Once the bash startup scripts are set the following commands can be used to switch between versions in your command line.
$ setjdk 1.7
$ java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
To switch back to Java 1.8 and verify your version. Run the following commands.
$ setjdk 1.8
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
If you are running specific apps on different JDKs then the easiest way is probably to create a script for each app. You just have to set the appropriate environment variables and then fully path the java executable you want.
The variables you set should be temporary--just for the life of the script.
This isn't a bad idea for all java apps you have anyway rather than typing "Java -jar xxx" all the time.
If you want to run the same app with 2 different versions of java (testing, for instance) then you either need 2 launch scripts for your app or Pritam's solution.

Mac OS java home ambiguty

Please see these 3 commands and their outcomes in MacOS:
Korays-MacBook-Pro:~ koraytugay$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
Korays-MacBook-Pro:~ koraytugay$ java -version
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)
Korays-MacBook-Pro:~ koraytugay$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home
Why does the first one return 1.8? What exactly is /libexec/java_home ?
Koray,
As per the Oracle docs...
JAVA_HOME is just an environment variable used to trigger the 'java' found in your PATH to use a different JDK image. Unfortunately, not all 'java' startup scripts obey this env variable. It's also used by many java tool startup scripts to determine what 'java' to run, bypassing the 'java' found in the PATH setting. Setting this variable during a JDK build is a bad idea, don't do it.
I use Eclipse myself, and don't have a JAVA_HOME env variable defined, here is my output running the same commands.
brandon#brandons-mbp ~
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
brandon#brandons-mbp ~
$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
brandon#brandons-mbp ~
$ echo $JAVA_HOME
Not sure why you have two different versions but did you try updating your JDK recently? Maybe when you upgraded it failed to launch a script to update your $JAVA_HOME.
Here's the instructions for installing JDK and setting JAVA_HOME on *nix based OSes.
Let me know if that helps I can help you dig deeper if need be.

Setting the JVM via the command line on Windows

Is it possible to specify the JVM to use when you call "java jar jar_name.jar" . I have two JVM installed on my machine. I can not change JAVA_HOME as it may break code that is all ready running.
Kind Regards
Stephen
Yes - just explicitly provide the path to java.exe. For instance:
c:\Users\Jon\Test>"c:\Program Files\java\jdk1.6.0_03\bin\java.exe" -version
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)
c:\Users\Jon\Test>"c:\Program Files\java\jdk1.6.0_12\bin\java.exe" -version
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)
The easiest way to do this for a running command shell is something like:
set PATH=c:\Program Files\Java\jdk1.6.0_03\bin;%PATH%
For example, here's a complete session showing my default JVM, then the change to the path, then the new one:
c:\Users\Jon\Test>java -version
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)
c:\Users\Jon\Test>set PATH=c:\Program Files\Java\jdk1.6.0_03\bin;%PATH%
c:\Users\Jon\Test>java -version
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)
This won't change programs which explicitly use JAVA_HOME though.
Note that if you get the wrong directory in the path - including one that doesn't exist - you won't get any errors, it will effectively just be ignored.
You should be able to do this via the command line arguments, assuming these are Sun VMs installed using the usual Windows InstallShield mechanisms with the JVM finder EXE in system32.
Type java -help for the options. In particular, see:
-version:<value>
require the specified version to run
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
yes I often need to have 3 or more JVM's installed. For example, I've noticed that sometimes the JRE is slightly different to the JDK version of the JRE.
My go to solution on Windows for a bit of 'packaging' is something like this:
#echo off
setlocal
#rem _________________________
#rem
#set JAVA_HOME=b:\lang\java\jdk\v1.6\u45\x64\jre
#rem
#set JAVA_EXE=%JAVA_HOME%\bin\java
#set VER=test
#set WRK=%~d0%~p0%VER%
#rem
#pushd %WRK%
cd
#echo.
#echo %JAVA_EXE% -jar %WRK%\openmrs-standalone.jar
%JAVA_EXE% -jar %WRK%\openmrs-standalone.jar
#rem
#rem _________________________
popd
endlocal
#exit /b
I think it is straightforward. The main thing is the setlocal and endlocal give your app a "personal environment" for what ever it does -- even if there's other programs to run.
If you have 2 installations of the JVM.
Place the version upfront.
Linux : export PATH=/usr/lib/jvm/java-8-oracle/bin:$PATH
This eliminates the ambiguity.

Categories

Resources