JAVA_HOME not defined correctly - java

I am attempting to update Jasper Reports Server, and having an issue with Java. It uses Tomcat to run java. I did not install java on this server, and I am not very familiar with java. Java was installed in a folder called /opt/jasperreports-server-cp-5.0.0/apache-tomcat/java/bin/. I do not believe Java was installed correctly, and it is telling me that the JAVA_HOME is not defined correctly.
We cannot execute /opt/jasperreports-server-cp-5.0.0/apache-tomcat/java/bin/java
Java is located in that directory.
I ran the following in a bash shell:
export JAVA_HOME=”/opt/jasperreports-server-cp-5.0.0/apache-tomcat/java”
export PATH=$JAVA_HOME/bin:$PATH
Can you please help me on what I am doing wrong when setting the JAVA_HOME, or does it have something to do with the java folder? should I reinstall Java altogether?

You say the file /opt/jasperreports-server-cp-5.0.0/apache-tomcat/java/bin/java exists, right ?
Can you execute it ? Can it execute standard jar file ?

Maybe you do not have execute permission for anything inside the $JAVA_HOME path.
You should try using chmod to give execute permission (atleast to bin/java ) , though I would just give to all files. Example -
chmod -R +x /path/to/<folder>/
or for a single file
chmod +x /path/to/file
also, can you please try the export JAVA_HOME without the double quotes and check -
export JAVA_HOME=/opt/jasperreports-server-cp-5.0.0/apache-tomcat/java

Related

Adding Java home not working on windows ZSH

I have java installed and set up properly and works fine with the normal Windows Powershell. However, I'm trying to make java work with the ZSH terminal and I cannot get it to work.
My JAVA_HOME (in powershell) is set to this path:
C:\Program Files\Java\jdk-15.0.2
Im trying to add this line to my .zshrc file:
export JAVA_HOME=`/mnt/c/"Program Files"/Java/jdk-15.0.2`
but when i do source .zshrc it says permission denied to that file. Running sudo chmod doesnt seem to help either. Am i doing something wrong or missing some other line to add? Most tutorials for ZSH is on a Mac OS so i dont know if it differs being that im in windows...
The backticks are trying to "execute" that folder as a shell command.
Double quotes will store that variables as a string
export JAVA_HOME="/mnt/c/Program Files/Java/jdk-15.0.2"
But this doesn't guarantee that java command itself will work.

Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java when i run gradle command in terminal

I am working in Ubuntu 16.04. I need to install gradle and the gradle is installed when i checked with sudo apt list --installed command but when i use gradle -version command it shows the following error,
JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java
In sudo vim /etc/environment file,
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/"
http_proxy="http://username:password#IP:port no/"
https_proxy="https://IP:port no/"
ftp_proxy="ftp://IP:port no/"
I don't know where i made mistakes. Please help me.
Thanks.
On a 64bit openSuse 64 42.1 box;
readlink -f $(which java)
provided;
/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/jre/bin/java
But;
export JAVA_HOME=/usr/lib64/jvm/jre-1.8.0-openjdk
is the path that worked and allowed java emulator to run.
So i think we have to manually browse our file system and see what path to choose.
Today I faced this problem. I am using the default java that comes with your linux distro (so in my case, linux mint).
$ whereis java
This command gave me
java: /usr/bin/java /usr/share/java
So, I opened /user/bin. There was a link to Java. I right clicked it and selected follow original link. This lead me to /usr/lib/jvm/java-11-openjdk-amd64/bin/java.
So now that I know where this java is, I opened my .bashrc file, and edited the JAVA_HOME.
So for my case,
## My Custom variables
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
This solved the problem.
Now if you are using some other java (say you downloaded from oracle and extracted the zip file ...), then you have to add that location. So for example, if your java is in /home/user/.sdkman/candidates/java/current, then
export JAVA_HOME=/home/user/.sdkman/candidates/java/current
export PATH=$JAVA_HOME/bin:$PATH
I see a mismatch. In your enviornment file the JAVA_HOME is set to "/usr/lib/jvm/java-8-openjdk-amd64/" and your mentioned that the error that you got relates to the JAVA_HOME as "/usr/lib/jvm/java-8-oracle/jre/bin/java"
If you JAVA is really installed in /usr/lib/jvm/java-8-oracle directory, then you need to ensure that the JAVA_HOME is set to that directory. And also your PATH reflects $JAVA_HOME/bin in it.
I typically install Oracle JDK/JRE separately in a separate directory such as /usr/local/jdk1.8.0 etc.
check the jvm installtion folder from Files
eg : /usr/lib/jvm/java-12-oracle
then in terminal run sudo nano /etc/environment and add the line
JAVA_HOME="/usr/lib/jvm/java-12-oracle"
Then open terminal and run
export JAVA_HOME="/usr/lib/jvm/java-12-oracle"

Not able to set JAVA_HOME variable in ubuntu 14.04 on manual installation

I've downloaded java jdk1.8.0.7.tar.gz file from the official website and unzipped it into my home directory. Now to set the $JAVA_HOME variable I used the follwing commands command nano .bashrc and then appending export $JAVA_HOME=/home/shivam/Java/jdk1.8.0.7 at the end of the file . But whenever I run the command sudo $CATALINA_HOME/bin/startup.sh I get an error message saying
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
I don't understand why it is unable to find the java path though I've installed tomcat and set its home variable the this way, which worked.
I wan't to install Java manually without using apt-get. Kindly guide .
You want to append the following to .bashrc:
JAVA_HOME=/home/shivam/Java/jdk1.8.0.7
Note the missing $ at the start.
Also remember that the file won't effect your current shell without sourceing it first.
Also, when running a command with sudo, you are running it as the root user, not as yourself. So the environment variable needs to be set for the root user, not yourself.
You can run sudo env | grep JAVA_HOME to see whether it is set for root.
Have you run .bashrc ?
source .bashrc
Try add the following 2 lines in your .bashrc file:
JAVA_HOME=/home/shivam/Java/jdk1.8.0.7/
export JAVA_HOME

Mac launcher script for Java app

I need to launch a Jar file with a portable JRE. It works on Windows thanks to launch4j, it works on Ubuntu thanks to me, but not on Mac ..... and I can't test it.
The path tree of application:
abcmap/
launcher.command
bin/
abcmap.jar
jre/
bin/
java
Thinking it's like Unix system, I tried this (without specify bash):
./bin/jre/bin/java -Xms512m -Xmx1024m -jar ./bin/abcmap.jar
But this error appear:
MacBook-Pro:~ frcstnt$ /Applications/abcmap-mac/abcmap.command;
exit;
/Applications/abcmap-mac/abcmap.command: line 1:
bin/jre/bin/java: No such file or directory
logout
All files are rwx for all,
All files are UTF8 without BOM
I tried to change end of line to Unix and to "Old Mac" with Notepad++,
Archives are available on my website:
http://abc-map.fr/download/
https://translate.google.fr/translate?hl=fr&sl=fr&tl=en&u=http%3A%2F%2Fabc-map.fr%2F
Someone can help me please?
Edit: I think my problem is in the launcher, maybe encoding or bad command ?
Edit: Thanks to the Wim's answer it works. This is the script:
#!/bin/bash
SCRIPTDIR=$(dirname $0)
cd $SCRIPTDIR
${SCRIPTDIR}/bin/jre/bin/java -jar ${SCRIPTDIR}/bin/abcmap.jar
The path ./bin/jre/bin/java will be resolved relative to the current directory, not relative to the location of the command file. Try what happens if you run the command from the directory where the command is located.
I think I've found thanks to Wim Deblauwe. I use this:
#!/bin/bash
SCRIPTDIR=$(dirname $0)
cd $SCRIPTDIR
${SCRIPTDIR}/bin/jre/bin/java -jar ${SCRIPTDIR}/bin/abcmap.jar
Find the script dir, go to this dir and start operations.
It seems like you maybe don't even have the Java Runtime Evironment installed. You should try running java -version or at least java -h or java --help.
If you output is something like the following:
java: command not found
You should download and install the latest JRE and try again.
If, however, you see your java version, try first using cd to go to the directory of your jarfile and then use:
java -jar -otheroptionshere jarfile.jar
I hope this helps! Tell me, if you still got issues.

how to run jar file on RHEL5?

I have made a jar file which i tested in windows and it works fine. now i want to test it for red hat enterprise linux 5. but i dont know how to run jar files in rhel5.
i've tried java -jar My.jar but it says bash: java: command not found. i've set JAVA_HOME variable as export JAVA_HOME=/root/jdk1.6.0_21 but still not working.
can anybody tell me how to run jar file in rhel5?
You need to set PATH variable , something like
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
replace /usr/java/jdk1.5.0_07/bin with path to your jdk's bin directory.
The problem is your terminal tries to find java command from the PATH , but it couldn't find it.
Update:
You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:
# vi /etc/profile
Next setup PATH / JAVA_PATH variables as follows:
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
Top tip but slightly off topic.
1) Install your JDK in /usr/local/jdkX.X.X_XX/
2) Create a symbolic link /usr/local/java -> your chosen JDK installation
When you install new versions of java or if you want to revert to an older version, just change the symbolic link.

Categories

Resources