Make $JAVA_HOME easily changable in Ubuntu
Put the environment variables into the global /etc/environment
file:
...
export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun
...
Execute "source /etc/environment" in every shell where you want the variables to be updated:
$ source /etc/environment
Check that it works:
$ echo $JAVA_HOME
$ /usr/lib/jvm/java-1.5.0-sun
Great, no logout needed.
If you want to set JAVA_HOME environment variable in only the terminal, set it in ~/.bashrc file.
JAVA_HOME variable gets reset
Sounds like you need to set that JAVA_HOME variable in ~/.profile (this is assuming you are using bash as your $SHELL)
vi ~/.profile
add
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
then exit the terminal and start a new one and you'll see that in your session.
env | grep JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-8-oracle
How to fix The JAVA_HOME environment variable is not defined in Ubuntu Server
Have a look at this.
Execute "source /etc/environment" in every shell where you want the
variables to be updated:
$ source /etc/environment
If you want to set JAVA_HOME environment variable in only the
terminal, set it in ~/.bashrc file.
EDIT: In the case of the original post, all that needed to be done was to reboot the server.
How to config Java 9 in Ubuntu
Installation and Configuration of JDK9 is step by step given below:
Install JDK9 in Ubuntu:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java9-installer
Make it as default:
sudo apt-get install oracle-java9-set-default
Changed in .bashrc, /etc/environment and also set default using
3 sections to change java configuration.
.bashrc:
export JAVA_HOME=/usr/lib/jvm/java-9-oracle
export PATH=$JAVA_HOME/bin:$PATH
/ect/environment:
JAVA_HOME="/usr/lib/jvm/java-9-oracle"
PATH=$PATH:$JAVA_HOME/bin
Then run the following command and set
sudo update-alternatives --config java
sudo update-alternatives --config javac
Then run the command
source /etc/environment
Check in terminal:
java -version
echo $JAVA_HOME
which java
which javac
Issue#1:
Execute "source /etc/environment" in every shell where you want the variables to be updated:
$ source /etc/environment
Resource Link: https://stackoverflow.com/a/5994031
Issue#2:
Just write JAVA_HOME="/usr/lib/jvm/java-9-oracle"
on your /etc/environment
, without the "export"
/etc/environment is supposed to contain a set of environment variables given as key=value pairs. It is not a shell script, so you can't use shell commands such as export in it.
Resource Link:
How to properly set JAVA_HOME in /etc/environment
Issue#3:
To check if java is properly installed:
$ which java
$ which javac
You should get similar output:
/usr/bin/java
Resource Link: https://stackoverflow.com/a/23124805
Issue#4:
To remove Oracle JDK completely, run the commands below:
Completely remove criteria:
sudo apt-get remove oracle-java9-installer
sudo apt-get remove --auto-remove oracle-java9-installer
sudo apt-get purge oracle-java9-installer
sudo apt-get purge --auto-remove oracle-java9-installer
Resource Link:
https://www.howtoinstall.co/en/ubuntu/trusty/tomcat7?action=remove
Java not picking up on environmental variable
You need to export the variable
export MY_VAR=stackoverflow
java -jar /path/to/my.jar
then you can print the value with
System.out.print(System.getenv("MY_VAR"));
edit: short example script (amend the path if necessary)
#!/bin/sh
MY_VAR="foobaz not exported"
echo "MY_VAR: ${MY_VAR}"
java -jar my.jar
export MY_VAR="foobaz exported"
echo "MY_VAR: ${MY_VAR}"
java -jar my.jar
Netbeans can build and run the java executable; but when executing application outside of Netbeans it doesn't run
Unsupported major.minor version 51.0
Those classes were created using a 1.7 SDK without the cross-compilation options. Use the cross-compilation options options to compile code for whatever is the minimum target version of the app.
Set default memory limit for all applets
I just had a look at the source code of the icedtea-web plugin. The part of the code which builds the command line seems to have no provision at all for including custom arguments, no matter their origin. So it does not matter which config files, HTML files or environment variables I edit, the code there will build the same command line to call java, disregarding all my whishes.
So if all configuration fails, what remains is hackery. One approach would be to patch the source code of the plugin, and make it include additional words into its command line. For a static addition, i.e. a single size change, this would be fairly easy. A more general fix would include the content of some environment variable, the way Peter's answer suggests. That would mean word-splitting the environment variable in question, and allocating the space for the array of words dynamically. Quite a bit of work at the C level.
As an alternative, one could tackle this at the level of the executed binary. The plugin apparently has the path of the executable hard-coded into it. In my case, this path is /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
. One can rename that binary to java.orig
, and put a shell script in its place, with the following content:
#!/bin/bash
for i in "$@"; do
if [[ "${i}" == sun.applet.PluginMain ]]; then
exec "$0.orig" -Xmx512m "$@"
fi
done
exec "$0.orig" "$@"
One consequence of this approach is the fact that ps
will no longer print these applets as java
but instead as java.orig
. Should not be a problem in most cases.
Related Topics
Finding Which Process Was Killed by Linux Oom Killer
How to Debug the Linux Kernel With Gdb and Qemu
Sed In-Place Flag That Works Both on MAC (Bsd) and Linux
How to Prevent a Background Process from Being Stopped After Closing Ssh Client in Linux
"Unable to Find Remote Helper For 'Https'" During Git Clone
Difference Between Clock_Realtime and Clock_Monotonic
How to Automatically Redirect Http to Https on Apache Servers
Get Exit Code of a Background Process
Linux Blocking Vs. Non Blocking Serial Read
How to Generate a Core Dump in Linux on a Segmentation Fault
What Does $@ Mean in a Shell Script
What Happens to an Open File Handle on Linux If the Pointed File Gets Moved or Deleted
Confused About Stdin, Stdout and Stderr
Core Dump File Is Not Generated