set System.getenv in Linux - java

Im building some application, where i would like to get some variable directly from linux.
I know, that the command to get the variable is System.getenv(), but i don't exackly know where i should set variable in linux.
I'm using Centos, and my tomcat is set in /usr/share/tomcat6
I was thinking, that maybe i should write it in /etc/profile file, but it doesn't works, and additionally i think that i should past the variable in user folder. User for Tomcat is tomcat, and his folder is /usr/share/tomcat6.
Should i create there file profile and add something like this? :
MY_VARIABLE=value
export MY_VARIABLE
Please help

From Terminal:
gedit ~/.bashrc
~ here refers to /home/USER directory.
Edit the file:
MY_VARIABLE=value
export MY_VARIABLE
confirm changes:
echo $MY_VARIABLE

Related

How to set environment variables permanently in Mac OS 10.15.6?

I have tried all approaches I can find online, but none of them works.
I want to set JAVA_HOME and PATH environment variables permanently, so that in IntelliJ I can issue commands like "mvn".
I have written my script into .bash_profile as shown below:
screenshot
But after I restarted my Mac and issued echo $JAVA_HOME, the output is still empty.
I also tried launchd.conf as said in this answer, but it didn't work either.
Could someone help me here?
Thanks in advance!
For osx add this in your ~/.profile or if you are using zsh inside ~/.zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home
restart your terminal or simply apply your changes
source ~/.profile
refer this to know more about related to this question
& also refer this to know more about installation process of Amazon Corretto 8.
If you are using zsh you can import .profile config inside ~/.zprofile
emulate sh
. ~/.profile
emulate zsh
Check your enviroment variables with
env
then check if your config files are in the right directory. Read /etc/profile e.g.
nano /etc/profile
There can you find the path to bashrc file

JAVA_HOME is not set currently. Please set JAVA_HOME in mac

JAVA_HOME is not set currently. Please set JAVA_HOME. I want to run appium programs but its throwing this weird error
Even java_home path not displaying in terminal. Currently displaying blank
My bash profile
JAVA VERSION Is also getting displayed
try the following command:
vim .bash_profile (do you see export JAVA_HOME=$(/usr/libexec/java_home) under the file) ?
If not then you need to add it there.
If already added then run source .bash_profile, it reloads the file. And the path is set.
The first bash line is incorrect.
export JAVA_HOME=$(/usr/libexec/java_home)
Should be:
export JAVA_HOME=/usr/libexec/java_home

./d2j-dex2jar.sh Not found

I have installed all the files. sh but I keep giving this error I can do?
enter image description here
I had the same issue, setting JAVA_HOME as usual won't do unfortunately. You need to set the java binary to be accessible anywhere in the terminal by adding it to your $PATH like so:
export PATH=$PATH:$JAVA_HOME/bin
Then it should work fine :)

classpath echo returns blank in linux

I just open file :.bash_profile
export JAVA_HOME=/usr/java/jdk1.8.0_91/bin
Now in command prompt when I fire command : echo $JAVA_HOME , It returns me blank.
Am I missing anything? I am trying to set permanent class path in linux.
I have read and follow many similar questions but still no success.
The contents of .bash_profile are only executed when you start a Login Shell. This is what happens if you, say, log in, or if you run bash --login.
The file you're probably looking for is ~/.bashrc, which is sourced by bash (i.e. executed) every time you start bash. You should put your export there.
Alternatively, on Linux you could put the line JAVA_HOME=/usr/java/jdk1.8.0_91/bin in the file /etc/environment, which should do exactly what you're trying to do (but you need to log out and log in first). This will be system-wide, though.
(for the record, the system-wide .bashrc file is /etc/bash.bashrc)
EDIT: Protip: You can check your environment variables in BASH by typing export with no arguments.
If your .bash_profile doesn't read also .bashrc, you need to add the above export also to .bashrc.
Or, you could add:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
And add everything in .bashrc from now on.

default value of JAVA_HOME seems to be overwriting the value set by: /etc/profile.d/java.sh

I've created a file /etc/profile.d/java.sh that includes (among other things) the line of code: export JAVA_HOME=/usr/java/jdk1.6.0_30. However, when I log in via SSH or reboot the linux Centos 6.2 server, I always see:
[root#host3 /etc/profile.d]# echo $JAVA_HOME
/usr/local/jdk
This is a new installation and server, so there's not much else done. It seems that the java.sh file is executing upon reboot or SSH login, however, the value of JAVA_HOME is being overwritten by the default value of /usr/local/jdk somehow. There isn't even a directory jdk under /usr/local.
Any idea how to correct this? The value of JAVA_HOME needs to be set (as done in java.sh) for all users.
UPDATE 1:
I checked the /etc/profile file and searched for the text jdk as well as JAVA and neither were found. I also checked the /root/.bash_profile and it shows as follows:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
Also, if I source java.sh, everything gets set correctly. But if I reboot server, JAVA_HOME goes back to /usr/local/jdk.
Check the /etc/profile file or the .bash_profile/.profile in your home directory.
It appears that cPanel adds the following lines to the /etc/bashrc file to set the JAVA_HOME to it's default.
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/classes.zip
So, if you have cPanel installed, make sure you check this file as well.

Categories