IntelliJ - why does the terminal has different environment variables values - java

I have recently replaced Java 7 to Java 8.
All regular apps in IntelliJ runs smoothly.
All but the tomcat apps - which run from the cmd command line but not from IntelliJ.
It fails to load due to an error in the JRE_HOME definition.
I have oviously defined JRE_HOME in the env variables and in the jdk settings.
I have executed
echo %jre_home%
both in the IntelliJ terminal and in the cmd and received different values
(IntelliJ terminal showed unupdated value.).
Where are the variables in the terminal declared?
How do I change them?

I don't know about old IntelliJ versions, but in 2019.2.3 one can configure environment variables in project settings. Be aware, you need to restart existing terminal or create new terminal tab to see the effect.

Almost 5 years later, I have the same issue on Windows 10 and had to restart my computer to solve it.
Edit:
The best solution is to not define a JRE_HOME environment variable. I don’t know why but IntelliJ stucks using that env variable.

If you are launching IntelliJ via the JetBrains ToolBox it will cache the $PATH variable so recent changes will not appear.
Just close and re-open JetBrains Toolbox.

For me it was because IntelliJ IDEA did not launch the shell as a "login" shell. All of my environment variables are set as I expect in a login shell, but in a non-login shell, many of them are missing.
By way of example, I expect /usr/local/bin to be in my PATH, but that is only true within login shells (as I get when I run iTerm2). This is an excerpt from a terminal session within IntelliJ IDEA:
amacleod#valjean ~> echo $PATH | grep -c /usr/local/bin
0
(1) amacleod#valjean ~> $SHELL --login
Welcome to fish, the friendly interactive shell
amacleod#valjean ~> echo $PATH | grep -c /usr/local/bin
1
One possible workaround would be to add my expected PATH and other variables to the shell configuration for non-login shells, but I would really rather just always be in a login shell.
I would have hoped that IntelliJ IDEA would have a checkbox for sending --login in the Terminal settings. However, it is possible to override the Shell path setting to include the login flag.

Invalidating the systems cache should do the trick. see JetBrains: Invalidate Cache.
Any other measures (like closing projects and IDE seemed to work only on a per project basis and only after a while (when IDE detected that the cache is invalid by itself ...)
Edit:
Correction - Unfortunately, after having the corrected the environment in all terminals for a while, IntelliJ "reverted" to the old, incorrect environment in any of my projects. Now I hope that after a reboot - as posted by akuman8 - the issue is solved. (If not, I will stick to a commandshell of my choice outside the IDE, where everything works fine ...)

For me, invalidating the system cache or restarting IntelliJ didn't reload the updated environment variables.
After restarting the computer, it enabled IntelliJ to pick up the updated environment variables.

AFAIKT, the intellij terminal on linux is just the same as running a standalone terminal session. It's just conveniently located in the IDE.
In response to the question, "How do I change [the terminal environment variables]?"
I'm using virtualenvwrapper to manage my terminal's environment variables for different environments, such as dev, test and production. It's working just as well for java development as it was for python development.
https://virtualenvwrapper.readthedocs.org

Close all IntellJ windows and any process that may currently be using the wrong SDK.
Navigate to the folder where your JDK is installed (e.g. C:\Program Files\Java).
Rename the wrong SDK so something else (e.g. jdk-11.0.5.OLD). If it won't do this, you may still have a process running using that SDK; go back to 1.
Start IntelliJ again.

It seems you can define project specific environment variables:
In IntelliJ project specific environment variables you can set under
Run/Debug configurations --> Defaults --> Application --> Environment
variables
from:
http://emmanuelbernard.com/blog/2012/05/09/setting-global-variables-intellij/#comment-617922540

Related

Picked up _JAVA_OPTIONS in kali linux

Each time i execute java code i get this message:Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
This problem has solution for windows os but i can't find any solution for linux os.
I found a solution to this problem, I lost a lot of time of course. I'm definitely not sure what creates this situation, in my case it happened after installing NetBeans and changing the text display settings, I turned on anti-aliasin.
These settings are defined in these configuration files, just remove them:
/etc/X11/Xsession.d/90kali-themes.conf
/etc/environment.d/95kali-themes.conf
Java Option disabling in terminal
if your using java11-jdk in linux this might be working for disabling the java option from displaying in terminal.
_SILENT_JAVA_OPTIONS="$_JAVA_OPTIONS" && unset _JAVA_OPTIONS && alias java='java "$_SILENT_JAVA_OPTIONS"'
This is not warning, it is information.
It literally says that some settings were picked up from _JAVA_OPTIONS environmental variable. It is used to configure some switches "globally" for every java application that will be run in given environment. You must have this set either on system or user level. If you remove that variable, information will be gone.
ON Kali Linux ANDROID STUDIO
This information comes because an environment variable called _JAVA_OPTIONS setup by default. I solved it by Unseating the variable.
**To unset the value of this variable, use unset _JAVA_OPTIONS.
After that Android Studio will no longer display the information and Android Studio will be able to build projects that were previously failing to build..

Update to IntelliJ 2017.1 causes JAVA_TOOL_OPTIONS to print

This morning I updated to IntelliJ IDEA 2017.1, when I run any of my tests, and even run a hello_world project I made, the console prints a message stating Picked up JAVA_TOOL_OPTIONS: -agentpath:"C:\windows\FireEye\JavaAgentDll_00.dll" after executing my program.
Also, when I try to run in debug mode I receive the error:
ERROR: JDWP unable to get necessary JVMTI capabilities.
If I run the program outside of IntelliJ I do not receive these errors. Is there a solution to resolving the error and is there a reason the JAVA_TOOL_OPTIONS is now "picked up"?
Remove this environment variable from the system or configure the run/debug configuration to not include parent environment:
I solved this problem by adding the following command into idea.bat file:
UNSET JAVA_TOOL_OPTIONS
I'm running IntelliJ 2017.1 on Windows 7, and my idea.bat file is located at C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2017.1\bin folder.
The top 5 lines of my idea.bat file looks like these after the changes:
#ECHO OFF
UNSET JAVA_TOOL_OPTIONS
::----------------------------------------------------------------------
:: IntelliJ IDEA startup script.
::----------------------------------------------------------------------
I've had the same problem at work. This is probably FireEye knowledge rather than an IntelliJ answer, but I find that when I run IntelliJ as administrator the problem goes away without any settings changes, so this works if you have admin access to the development box.
Note that if you start IntelliJ from the IDEA toolbox then the toolbox also needs to be run as adminstrator.
Another way to override the env is from the from the Help | Edit Custom VM Options menu of all places.

Error: JAVA_HOME is not set and could not be found after Eclipse installation

Actually I installed hadoop successfully. hadoop version command worked fine. Now I wanted to run the map reduce program. So I installed eclipse. After which I am getting an error saying "Error: JAVA_HOME is not set and could not be found."
Even echo $JAVA_HOME command in cygwin terminal did not print the value after eclipse installation.
How can I fix this issue first?
How can I run the MaxTemperature map reduce program using eclipse.
Thanks
Try to set JAVA_HOME. You can do this by editing your env.sh such that it will have:
export JAVA_HOME=/absolute/path/to/your/java/home
In case the path contains spaces, surround it with double quotes.
Example:
export JAVA_HOME="/cygdrive/f/program files/java/jdk1.7.0_51"
You may need to refer to Eclipse Runtime Options.
I would try first to launch Eclipse with the -clean option
If that does not work, try launching Eclipse with -vm path to java vm
There are things you can do to modify the .ini file directly, but if these two fails, try to reinstall Eclipse. Remember, the java.exe exists in multiple locations on your PC. Changing your PATH variable manually might help you with Eclipse, but it may break other things. This is why some products use %JAVA_HOME% to distinguish from the Java that might be loaded before it.
If you want to really know what is going on with your Java installation, open a command prompt window and type c:\> where java.
As you can see, I have Java installed in multiple locations AND multiple versions of Java (7 and 8). It is important that you know these things before you start messing with environment variables.

error when installing Java EE SDK on Linux

I did have JDK installed, and also put $JDK_HOME/bin on my PATH. However, I still have problem to install Java EE. Could you guys give me some hints? Thanks.
dav#Bruno:~$ ls
[some stuff...]
33511405_3645.jpg glassfish stuff
bea hplip-3.11.12-plugin.run temp
bin hpscan001.png Templates
C03_08.txt java_ee_sdk-6u4-jdk7-linux.sh Tomcat
c4c jdk1.7.0_10 Ubuntu One
[some stuff2...]
dav#Bruno:~$ echo $PATH
/home/dav/jdk1.7.0_10/lib:/usr/share/java:/home/dav/jdk1.7.0_10:/home/dav/jdk1.7.0_10/bin:/home/dav/Fluent.Inc/bin:/home/dav/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/dav/jdk1.7.0_10/lib:/usr/share/java
dav#Bruno:~$ sudo sh java_ee_sdk-6u4-jdk7-linux.sh
Could not locate a suitable jar utility.
Please ensure that you have Java 6 or newer installed on your system
and accessible in your PATH or by setting JAVA_HOME
dav#Bruno:~$
I think the problem you're facing is that the PATH variable you're looking at is set for the user 'dav', but because you're sudoing the sh command, the PATH changes to that of root, which probably doesn't contain the JDK.
I think you should try explicitly setting the JAVA_HOME environment variable, try running:
sudo JAVA_HOME=/home/dav/jdk1.7.0_10 sh java_ee_sdk-6u4-jdk7-linux.sh
in case someone still gets frustrated over this:
("Could not locate a suitable jar utility.
Please ensure that you have Java 7 or newer installed on your system
and accessible in your PATH or by setting JAVA_HOME")
First of all make sure you are not using "sudo" to install java ee.
when you use sudo you use a different environment (root, with not necessarily the same
environment variables). in this case (ee installation) sudo is not required.
In other (which ever) cases when root access is required make sure the required user/system variables are set on system level, not (just) on user level.
to set variables at system level instead of user level define the variables in a system level script, i.e. /etc/profile or /etc/profile.d
otherwise, if you are not using SUDO trying to install jee, and still have this "JAVA_HOME not set"-problem, try this:
the cause seems to be the JAVA_HOME variable that can not be found by the install script.
therefore adjust ~/.bashrc to define JAVA_HOME.
JAVA_HOME of course has to point to your oracle java (se/jdk) installation. If you haven't installed it, that's the first thing to do. JAVA_HOME should point at the root directory of the installation (not to the bin directory in it), i.e.:
export JAVA_HOME=/usr/local/jdk1.7.1_02.
Next change path like so:
PATH=$JAVA_HOME:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
keep the faith
don't let frustrations get the better of you (perhaps making you take it out on your colleagues or loved ones :o )
don't allow stress to build up too much. take a break in time to watch a funny video or
take a stroll to the coffee machine, or have a little chat with that cute person a couple of desks away from you.
You'll need to create an update alternative for the "jar" executable like:
sudo update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/jdk1.6.0/bin/jar" 1
Note: You may need to use appropriate path in your case.

reading environment variables from java using Eclipse

Everywhere I search, it says you can get an environment variable by using System.getenv(str).
It's not working for me. Here's what I am doing:
OS : Mac OS x 10.7
Java 1.6.x
If I do export abc=/hello/ in my terminal and then echo $abc, it gives me the variable. If I close the terminal, reopen it again and do echo $abc, it's gone. To overcome this, I edited my .bash_profile file and inserted export abc=/hello/. Close the terminal, do echo $abc and it works. So I understood that the env variable is permanent now.
Now if in my java console app, I print System.getenv("abc"), it returns null. What am I missing?
The reason that you needed to put the export in your .bash_profile is that setting environment variables in a shell only persist the variables in that shell, and - since you used export - to children of that shell, or in other words, other programs launched by that shell.
If you're running your java code from Eclipse, and you launch Eclipse from a shell with your environment variables set, then your program should see the added environment variables. To launch Eclipse from the shell, you'll need to use the OS X open command:
$ open /Applications/eclipse/Eclipse.app
Alternately, you can set the environment variables within your Eclipse project, and you'll need to do this if you're not launching Eclipse from a shell with the proper environment. In the Run Configurations dialog, look for a tab named Environment. Here you'll find a table for adding environment variables that will be passed to your program.
It's better to add the environment variables to the Run Configuration since that way they'll always be available to your project. Your code doesn't actually care where the environment variables are coming from, and adding them to the project is simpler, and will work the same way on different platforms.
Of course, when you run your program outside Eclipse, you'll need to make sure that the same environment variables exist in the shell where you e.g. run java.
Eclipse does not use the system's env variables unless launched directly from the shell (which is how it is generally launched, by clicking its icon). In that case you will have to explicitly set the required env variables in the environment tab of the run configuration of the program.
I too faced The same issue , I resolved it this way.
Open Terminal
cd to the folder where eclipse.app is located E.g cd /Users/Shared/eclipse/jee-2020-09
Type open Eclipse.app/
Eclipse will now open and will be able to access the system environment variables as well.
Check it using the code:
System.getenv().forEach((k, v) -> {
System.out.println("ENV : " + k + ":" + v);
});

Categories