Why JAVA_HOME not recognized by tomcat7 in Ubuntu? - java

I have installed tomcat7 on my Ubuntu machine. When I try to restart the server I get message to set JAVA_HOME but it is set in .bashrc
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export CATALINA_HOME=/usr/share/tomcat7
Error:
omkars#<ubuntu_14.04>:~$ sudo service tomcat7 restart
[sudo] password for omkars:
* no JDK or JRE found - please set JAVA_HOME
omkars#<ubuntu_14.04>:~$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
What could be missing ?
Thanks.

Now, its working!
Changes I have done are:
changed .bashrc as explained in the question.
changed /etc/init.d/tomcat7 to point to oracle Java8 which is missing here!
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-7-oracle **/usr/lib/jvm/java-8-oracle**"
Then,
root#omkars-Dell-System-Inspiron-N4110:~# sudo service tomcat7 restart
* Starting Tomcat servlet engine tomcat7 [ OK ]
Got a hint from this page:
https://mifosforge.jira.com/wiki/display/MIFOSX/Install+Tomcat+7+on+Ubuntu+11.10+for+Mifos+X
Thanks

It seems like the preferred way of handling this is to uncomment the JAVA_HOME entry in /etc/default/tomcat7 and adjust the path accordingly. If you're using the webupd8 repository with the oracle-java8-installer, it's JAVA_HOME=/usr/lib/jvm/java-8-oracle.

It'll need to be set for the user that runs the tomcat service, rather than for your user.
Set it in the system wide profile, somewhere in /etc/profile or /etc/profile.d/, depending on how your machine is configured.

The startup script at /etc/init.d/tomcat7 sources the file /etc/default/rcS before searching for some well-known install locations.
Adding the line JAVA_HOME=/usr/lib/jvm/java-8-oracle to /etc/default/rcS corrects the no JDK or JRE found startup problem without directly modifying the /etc/init.d/tomcat7 script.

You can set an environmental variable in the setenv.sh script. According to the Running The Apache Tomcat 7.0 document:
Apart from CATALINA_HOME and CATALINA_BASE, all environment variables can
be specified in the "setenv" script. The script is placed either into
CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named
setenv.bat (on Windows) or setenv.sh (on *nix).
So just add the following line to setenv.sh:
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
This way you are setting the variable locally.

I have that same problem but I solve it by changing
JDK_DIR variable in /etc/init.d/tomcat as follow :
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-7-oracle /usr/lib/jvm/java-8-oracle"

Try install Java using the repository of http://www.webupd8.org .
This is for Java 8: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

Related

Can't run Apache james on mac Sierra

I'm using Apache James as email server for development purpose on mac Sierra - v 10.12.3
When I try to start/run it as super user
sudo ./run.sh
it I get the following error:
ERROR: JAVA_HOME not found in your environment.
Please, set the JAVA_HOME variable in your environment to match the
location of the Java Virtual Machine you want to use.
When I try to run it without sudo, I get the following:
Using PHOENIX_HOME: /Users/myUserName/Dev/james-2.3.2.1
Using PHOENIX_TMPDIR: /Users/myUserName/Dev/james-2.3.2.1/temp
Using JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
Running Phoenix:
Phoenix 4.2
James Mail Server 2.3.2.1
Remote Manager Service started plain:4555
org.apache.avalon.phoenix.containerkit.lifecycle.LifecycleException: Component named "pop3server" failed to pass through the Starting stage. (Reason: java.net.BindException: Permission denied (Bind failed)).
at org.apache.avalon.phoenix.containerkit.lifecycle.LifecycleHelper.fail(LifecycleHelper.java:354)
The JAVA_HOME variable has been set correctly so far I know.
When I type $JAVA_HOME in terminal I get:
-bash: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home: is a directory
in .profile and .bash_profile files I do have:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
Any idea what could the reason be please?
Resolved... the solution was to set the JAVA_HOME Environment Variable for Sudo. and this was done on: /etc/sudoers. I used 'vi' to edit the file via terminal.
sudo visudo
and then adding the following line after the Default settings for Environment Variables:
Defaults env_keep += "JAVA_HOME"
That's all. To Check if the JAVA_HOME Environment Variable has been set correctly for sudo, I just typed this command in the terminal.
sudo printenv

hadoop cannot start start-dfs.sh

I'm trying to install Hadoop and run it.
And I'm sure I've installed Hadoop and formatted namenode successfully.
However, when I tried to run start-dfs.sh, I got the error below:
localhost: starting namenode, logging to /usr/local/hadoop/logs/hadoop-wenruo-namenode-linux.out
localhost: /usr/local/hadoop/bin/hdfs: line 304: /usr/local/hadoop/usr/lib/jvm/java-8-oracle/bin/java: No such file or directory
My JAVA_HOME is below:
echo $JAVA_HOME
/usr/lib/jvm/java-7-openjdk-amd64
My hadoop-env.sh file:
export JAVA_HOME=${JAVA_HOME}
How could Hadoop is still looking for JDK8 as I already set JAVA_HOME to JDK7?
Thank you very much.
In general each Hadoop distribution/version should have a few basic script files that set this JAVA_HOME environment variablesuch as yarn-env.sh file if you have yarn.
Also depending on your hadoop version you might also have the path in your *-site.xml files such as hdfs-site.xml, core-site.xml, yarn-site.xml, mapred-site.xml, and a few others depending on what services you have. It is likely your update to hadoop-env.sh did not regenerate the client configuration files unless you did it through a cluster manager application then redeployed client configuration files.
Sometimes these also I find get to set use the systems bin/java executable. You can use the following command to find out what java your OS has in your bin/ path.
readlink -f /usr/bin/java
/usr/bin/java -version
Did you also update hadoop-env.sh on each node then restart all services to make sure it is picked up again?
Leave it. The problem is resolved.
In hadoop-env.sh, I changed export JAVA_HOME=${JAVA_HOME} to echo $JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64.
It looks like ${JAVA_HOME} doesn't work.

Artifactory environment variables on CentOS

I'm going mad.
/usr/lib/jvm/
has
java-1.7.0-openjdk-1.7.0.65.x86_64
java-1.7.0-openjdk-1.7.0.79.x86_64
Last night at the most unfortunate possible time, the contents of #65, which artifactory was apparently using, disappeared. Java disappeared. Maybe it was already gone, but the new Linux guys were 'upgrading' the machine, so it's suspicious.
Now, the issue is that artifactory cannot forget about version 65.
If I type in env or set, we're golden. No mention of v65. But artifactory lives in its own world.
[root#me]# service artifactory check
Checking arguments to Artifactory:
ARTIFACTORY_HOME = /var/opt/jfrog/artifactory
ARTIFACTORY_USER = artifactory
TOMCAT_HOME = /opt/jfrog/artifactory/tomcat
ARTIFACTORY_PID = /var/opt/jfrog/run/artifactory.pid
JAVA_HOME =
JAVA_OPTIONS = -server -Xms512m -Xmx2g -Xss256k -XX:PermSize=128m -XX:MaxPermSize=256m -XX:+UseG1GC
[root#me]# service artifactory start
Starting Artifactory tomcat as user artifactory...
Max number of open files: 32000
Using ARTIFACTORY_HOME: /var/opt/jfrog/artifactory
Using ARTIFACTORY_PID: /var/opt/jfrog/run/artifactory.pid
Using CATALINA_BASE: /opt/jfrog/artifactory/tomcat
Using CATALINA_HOME: /opt/jfrog/artifactory/tomcat
Using CATALINA_TMPDIR: /opt/jfrog/artifactory/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre
Using CLASSPATH: /opt/jfrog/artifactory/tomcat/bin/bootstrap.jar:/opt/jfrog/artifactory/tomcat/bin/tomcat-juli.jar
Using CATALINA_PID: /var/opt/jfrog/run/artifactory.pid
env and set shows
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk.x86_64
JRE_HOME=/usr/lib/jvm/java-1.7.0-openjdk.x86_64/jre
PATH is correct too.
ls -l shows
lrwxrwxrwx 1 root root 34 Jun 24 22:38 java-1.7.0-openjdk.x86_64 -> java-1.7.0-openjdk-1.7.0.79.x86_64
So it's pointing to the right place. Where in the hell is the artifactory user getting 65 from? If I try su artifactory, i go to bash-4.1$ indicating that artifactory isn't a user in the traditional sense, but even so, env and set are correct.
I finally managed to get it working by compromising.
/opt/jfrog/artifactory/bin
I edited artifactory.default and put my export JAVA_HOME in there, and started artifactory from that folder, instead of as a service. This will do until the next time the Linux team mess up my server.
But anyone know how I can get it running as a service?
Take a look in /etc/init.d/artifactory, which is the script that runs when you call "service artifactory ..." - it looks like something in there (possibly another script that is sourced in) is setting JRE_HOME to the old version.
You could also try
sudo su - artifactory; env | grep JRE
to make sure that the artifactory user's environment doesn't set JRE_HOME to the old version.
I had a similar issue after. Installed Artifactory 5.3.2 and months later ran a yum update on my Linux server. I saw the msg: "error artifactory tomcat server did not start in 60 seconds" The issue started after a I ran a yum update. The update impacted my version of java as noted below.
Verify Error Log
vi /var/opt/jfrog/artifactory/logs/catalina.out
--> /opt/jfrog/artifactory/tomcat/bin/catalina.sh: line 433: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el7_3.x86_64/bin/java: No such file or directory
vi /opt/jfrog/artifactory/tomcat/bin/catalina.sh
export JRE_HOME=/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64
export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64
cd /opt/jfrog/artifactory/tomcat/bin/
restart catalina
./catalina.sh
artifactory will restart and should show updated JRE_HOME

What should I set JAVA_HOME environment variable on macOS X 10.6?

Many Java applications that use shell scripts to configure their environment use the JAVA_HOME environment variable to start the correct version of Java, locate JRE JARs, and so on.
In macOS X 10.6, the following paths seem to be valid for this variable
/Library/Java/Home
/System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Versions/Current
Some of these are symlinks to the actual current VM (as defined in the Java Preference pane).
But which one should be used—or is it okay to use any of them?
I just set JAVA_HOME to the output of that command, which should give you the Java path specified in your Java preferences. Here's a snippet from my .bashrc file, which sets this variable:
export JAVA_HOME=$(/usr/libexec/java_home)
I haven't experienced any problems with that technique.
Occasionally I do have to change the value of JAVA_HOME to an earlier version of Java. For example, one program I'm maintaining requires 32-bit Java 5 on OS X, so when using that program, I set JAVA_HOME by running:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.5)
For those of you who don't have java_home in your path add it like this.
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /usr/libexec/java_home
References:
Oracle explains the java_home command
An article for configuring the JDK in Spring Tool Suite (Eclipse
2019) on MacOS
Also, it`s interesting to set your PATH to reflect the JDK. After adding JAVA_HOME (which can be done with the example cited by 'mipadi'):
export JAVA_HOME=$(/usr/libexec/java_home)
Add also in ~/.profile:
export PATH=${JAVA_HOME}/bin:$PATH
P.S.: For OSX, I generally use .profile in the HOME dir instead of .bashrc
I am having MAC OS X(Sierra) 10.12.2.
I set JAVA_HOME to work on React Native(for Android apps) by following the following steps.
Open Terminal (Command+R, type Terminal, Hit ENTER).
Add the following lines to ~/.bash_profile.
export JAVA_HOME=$(/usr/libexec/java_home)
Now run the following command.
source ~/.bash_profile
You can check the exact value of JAVA_HOME by typing the following command.
echo $JAVA_HOME
The value(output) returned will be something like below.
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
That's it.
I'm on Mac OS 10.6.8
The easiest solution works for me is simply put in
$ export JAVA_HOME=$(/usr/libexec/java_home)
To test whether it works, put in
$ echo $JAVA_HOME
it shows
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
you can also test
$ which java
Nowadays Java seems to be installed in /Library/Java/JavaVirtualMachines
I tend to use /Library/Java/Home. The way the preferences pane works this should be up to date with your preferred version.
That above works not any more in YOSEMITE for GRAPHICAL APPLICATIONS! Like eclipse, or anything started with Spotlight. (.bash_profile, launchd.conf works for terminal sessions only.)
Before starting eclipse, just open a terminal window, and give out the following command:
launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
(With your installation path! Perhaps works with $(/usr/libexec/java_home) instead of the full path too.)
View the whole excellent article about the permanent solution here:
Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan/macOS Sierra?
It is recommended to check default terminal shell before set JAVA_HOME environment variable, via following commands:
$ echo $SHELL
/bin/bash
If your default terminal is /bin/bash (Bash), then you should use #hygull method
If your default terminal is /bin/zsh (Z Shell), then you should set these environment variable in ~/.zshenv file with following contents:
export JAVA_HOME="$(/usr/libexec/java_home)"
Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.
This method tested working in macOS Mojave Version 10.14.6.
I've found this stack to help, i was having the same issue and i could fix:
My java path was here:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
and was needed to put into my .bash_profile:
export JAVA_HOME=\"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home\"
Hope help
As other answers note, the correct way to find the Java home directory is to use /usr/libexec/java_home.
The official documentation for this is in Apple's Technical Q&A QA1170: Important Java Directories on OS X: https://developer.apple.com/library/mac/qa/qa1170/_index.html
For me maven seems to work off the .mavenrc file:
echo "export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)" > ~/.mavenrc
I'm sure I picked it up on SO too, just can't remember where.
Create file ~/.mavenrc
then paste this into the file
export JAVA_HOME=$(/usr/libexec/java_home)
test
mvn -v
Skipping Terminal setup since you mentioned applications, permanent system environment variable set up (works for macOS Sierra; should work for El Capitan too):
launchctl setenv JAVA_HOME $(/usr/libexec/java_home -v 1.8)
(this will set JAVA_HOME to the latest 1.8 JDK, chances are you have gone through serveral updates e.g. javac 1.8.0_101, javac 1.8.0_131)
Of course, change 1.8 to 1.7 or 1.6 (really?) to suit your need and your system
For Fish Shell users, use something like the following: alias java7 "set -gx JAVA_HOME (/usr/libexec/java_home -v1.7)"

How to set JAVA_HOME for multiple Tomcat instances?

I have 2 Java Web Projects. One runs on JDK 1.5 and the other runs on JDK 1.6. I want to run both of them on the same computer, but the JAVA_HOME environment variable can only have one value. I want to set JAVA_HOME for each Tomcat server.
place a setenv.sh in the the bin directory with
JAVA_HOME=/usr/java/jdk1.6.0_43/
JRE_HOME=/usr/java/jdk1.6.0_43/jre
or an other version your running.
One thing that you could do would be to modify the catalina.sh (Unix based) or the catalina.bat (windows based).
Within each of the scripts you can set certain variables which only processes created under the shell will inherit. So for catalina.sh, use the following line:
export JAVA_HOME="intented java home"
And for windows use
set JAVA_HOME="intented java home"
If you are a Windows user, put the content below in a setenv.bat file that you must create in Tomcat bin directory.
set JAVA_HOME=C:\Program Files\Java\jdk1.6.x
If you are a Linux user, put the content below in a setenv.sh file that you must create in Tomcat bin directory.
JAVA_HOME=/usr/java/jdk1.6.x
Also, note that there shouldn't be any space after =:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_27
You can add setenv.sh in the the bin directory with:
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
and it will dynamically change when you update your packages.
In UNIX I had this problem, I edited catalina.sh manually and entered
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24
echo "Using JAVA_HOME: $JAVA_HOME"
as the first 2 lines. I tried setting the JAVA_HOME in /etc/profile but it did not help.
This worked finally.
I think this is a best practice (You may be have many Tomcat instance in same computer, you want per Tomcat instance use other Java Runtime Environment):
This is manual inside file: catalina.sh
# JRE_HOME Must point at your Java Runtime installation.
# Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
# are both set, JRE_HOME is used.
Linux based Tomcat6 should have /etc/tomcat6/tomcat6.conf
# System-wide configuration file for tomcat6 services
# This will be sourced by tomcat6 and any secondary service
# Values will be overridden by service-specific configuration
# files in /etc/sysconfig
#
# Use this one to change default values for all services
# Change the service specific ones to affect only one service
# (see, for instance, /etc/sysconfig/tomcat6)
#
# Where your java installation lives
#JAVA_HOME="/usr/lib/jvm/java-1.5.0"
# Where your tomcat installation lives
CATALINA_BASE="/usr/share/tomcat6"
...
I had the same problem my OS is windows 8 and I am using Tomcat 8,
I just edited the setclasspath.bat file in bin folder and set JAVA_HOME and JRE_HOME
like this...
#echo off
...
...
set "JRE_HOME=%ProgramFiles%\Java\jre8"
set "JAVA_HOME=%ProgramFiles%\Java\jdk1.7.0_03"
...
...
and it works fine for me now......
For Debian distro we can override the setting via defaults
/etc/default/tomcat6
Set the JAVA_HOME pointing to the java version you want.
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Just a note...
If you add that code to setclasspath.bat or setclasspath.sh, it will actually be used by all of Tomcat's scripts you could run, rather than just Catalina.
The method for setting the variable is as the other's have described.
I think you only need add in startup.sh or startup.bat the set JAVA_HOME=C:\Program Files\Java\jdk-19
After check...

Categories