The use of Java options environment variables detected. How to delete it? - java

When I turned Android Studio on Windows 10, I got this warning:
The use of Java options environment variables detected. Such variables
override IDE configuration files (*.vmoptions) and may cause
performance and stability issues. Please consider deleting these
variables: JAVA_TOOL_OPTIONS.
So, I want to delete this variable, but I don't know how. This similar query didn't help me because I don't see this variable in system variables. I suspect I must have set it via the command line when I was troubleshooting another issue. When starting the console of any IDE, the message:
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
Is also displayed. Can it be deleted somehow?

As mentioned in the other questions, you get that warning if starting any java process when the JAVA_TOOL_OPTIONS environment variable is declared. This is mentioned in Windows Android Studio logs on start-up, and also if you run java -version from a terminal / cmd.exe.
Before removing first check whether you need these addition settings or not. The setting -Dfile.encoding=UTF8 is default for JDK19 onwards, but not for earlier JDKs and fixing to avoid an Android Studio warning might cause unexpected changes elsewhere with other Java based applications on pre-JDK19.
Two places I know where it could be defined:
Settings > System > About > Advanced System Settings -> Environment Variables:
Delete JAVA_TOOL_OPTIONS values under your user settings or System settings.
This setting can be added back by re-entering in the dialog or typing command: setx JAVA_TOOL_OPTIONS blah.
Don't forget to close/re-open Windows Terminal or CMD.EXE after making changes to the environment variables or they won't see the new values.
As a local variable in CMD.EXE. This setting may have been added by some init script (say if you use CMD.EXE /k init.cmd) calling set JAVA_TOOL_OPTIONS=blah and this overrides / replaces 1) value.
You may be able to remove with set JAVA_TOOL_OPTIONS= and re-running java or Android Studio from that CMD, but note that the original value will be restored after close/re-open CMD if it was set in 1) already.
There is no doubt an easier way to do this as annoyingly it adds a blank cmd terminal: if you wished to disable for just Android Studio you could set up an alternative windows shortcut with this as "Target" field (do no add any extra spaces):
cmd.exe /c set JAVA_TOOL_OPTIONS=&&"C:\Program Files\Android\Android Studio\bin\studio64.exe"
Note:
setx VARNAME NEWVALUE does not need "=" sign.
set VARNAME=NEWVALUE requires the "=" sign

Related

Run a jar file only with jre [duplicate]

When trying to check the current version of Java in which I am running, I received the error "java is not recognized as an internal or external command, operable program or batch file.".
I am running Windows 7 OS and have downloaded the latest JDK and felt I may have accidentally deleted the java from machine as before I was able to check the Java version using the command "java -version".
What software must I download to get Java working on my machine again?
EDIT:
I have managed to get Java running from my cmd again after ensuring all environment variables pointed to the current Java SDK.
You need to configure your environment variables, JAVA_HOME and PATH.
JAVA_HOME must contain the path to java, and you should add %JAVA_HOME%\bin to PATH
Alternatively, you can simply add to your PATH the whole path to the bin folder, without the JAVA_HOME variable, however, this makes a little more annoying when you need to have more than one java version on your machine (that way you only need to change JAVA_HOME and don't even bother with PATH)
For Windows 7:
Right click on My Computer
Select Properties
Select Advanced System Settings
Select the Advanced tab
Select Environment Variables
Select Path under System Variables
Click on the Edit button
In Variable value editor paste this at the start of the line
C:\Program Files\Java\jdk1.7.0_72\bin;
Click Ok then Ok again
Restart command prompt otherwise it won't see the change to the path variable
Type java -version in the command prompt.
Notes on Step 8:
The version of java in this may be different from the one used here -- this is only an example.
There will probably be other values in the path variable. It is really important that you don't delete what's already there. That's why the instructions say to paste the given value at the start of the line -- this means that you don't remove the existing value, you just put java before it. This also fixes any problems you'd be getting if an other version of java is also on the path.
Notes on Step 6:
This sets the path for the computer, not for the individual user. It may be that you're working on a computer which other developers also use, in which case you'd rather set the user variables, rather than the system variables
It sounds like you haven't added the right directory to your path.
First find out which directory you've installed Java in. For example, on my box it's in C:\Program Files\java\jdk1.7.0_111. Once you've found it, try running it directly. For example:
c:\> "c:\Program Files\java\jdk1.7.0_11\bin\java" -version
Once you've definitely got the right version, add the bin directory to your PATH environment variable.
Note that you don't need a JAVA_HOME environment variable, and haven't for some time. Some tools may use it - and if you're using one of those, then sure, set it - but if you're just using (say) Eclipse and the command-line java/javac tools, you're fine without it.
1 Yes, this has reminded me that I need to update...
Assume, Java/JDK is installed to the folder: C:\Program Files\Java:
Follow the steps:
Goto Control Panel → System → Advanced system settings → Advanced → Environment variables (Win+Pause/Break for System in Control Panel)
In the System variables section click on New…
In Variable name write: JAVA_HOME
In Variable value write: C:\Program Files\Java\bin, press OK:
In the System variables section double click on Path
Press New and write C:\Program Files\Java\bin, press OK:
In Environment variables window press OK
Restart/Run cmd.exe and write: java --version:
Search environment variables.
open the "edit the system environment variables".
then click on "environment variables".
Under "User variables" click on "Path" then "Edit".
Find your Java path and click "Edit".
then paste the path of your java installation folder.
Mostly you can find it on a path similar to this.
C:\Program Files\Java\jdk-12.0.2\bin
Then click OK.
now in the start menu, type cmd.
open the command prompt.
type
java -version
If you did it right,it should show something like this.
For me its start working after putting ,: in the starting of the system variable path :--
My solution was to put same value (path to JDK bin folder) in JAVA_HOME and Path
In my case, PATH was properly SET but PATHEXT has been cleared by me by mistake with .exe extension. That why window can't find java or anything .exe application from command prompt. Hope it can help someone.
This problem is on Windows 8.
First copy your Path of java jdk - e.g. C:\Program Files\Java\jdk1.7.0_51\bin.
Right on the My Computer Icon on the Desktop and Click Properties.
Select 'Advanced System Settings' in the left pane.
Under 'Advanced' tab, select 'Environment Variables' at the bottom.
In System Variables, select 'Path' Variable and edit it.
Paste the path and add a ';' at the end - e.g. C:\Program Files\Java\jdk1.7.0_51\bin;
I had the same problem. Just Install the exact bit of java as of your computer. If your PC is 64 bit then install 64 bit java. If it is 32 bit then vice versa :)
Not sure why, but in my case, the reason was because I was running Anaconda terminal instead of the CMD.
After I use CMD and update the path settings as mentioned by all comments above the issue solved on my side.
In case you are using a laptop and do not have the Pause\Break button.
For windows 10 users with 20h2 and above:
1 WIN → type "About your PC" → scroll at the bottom → Advanced system settings → Environment variables or WIN+R → shell:::{bb06c0e4-d293-4f75-8a90-cb05b6477eee} to open Classic System Properties → on the left side → Advanced system settings → Environment variables
Also for Windows 10 and Windows 7:
1 WIN → This PC → properties → Advanced system settings → Environment variables
In the System variables section click on New…
In Variable name write: JAVA_HOME
In Variable value write: C:\Program Files\Java\jdk-15.0.2\bin, press OK
I have taken steps 2-4 from Vijay Bhatt
There is a bit faster way to set a system variable. Run a console (terminal) as an administrator.
General command synax to add a new variable:
setx variableName value /M
In our example, we would need to set it as
setx JAVA_HOME "C:\Program Files\Java\jdk-15.0.2\bin" /M`
Like this:
/M - flag specifies to set the variable in the system environment.
After command execution, you should see the message:
SUCCESS: Specified value was saved.
How can I check that it is added?
Close your active terminal;
Open your favorite terminal;
Type java -version.
You should see something similar to this:
Notice:
User variables can be created w/o having a root (administrator privileges), whereas to create System variable; You need to open a console as a root.
I have used C:\Program Files\Java\jdk-15.0.2\bin as an example, in your case, it could be different from mine.
I opened a new command prompt in Windows 10 after updating the environment variables without closing the old one(To have my commands handy and lazy to type again)
Still, the new cmd window was referring to the previous version of Java.
Then once I closed the all cmd prompts that ran with admin privileges, the new java version was getting reflected.
I corrected my path variable but command prompt need to Restart otherwise, it won't be able to verify the change to the path variable. May be helpful for someone like me. so
"restart command prompt"
Restart the command prompt before checking the version of JDK installed. I spent 02 days on it until my problem resolved when I restarted the command prompt before checking javac - version, javac etc.
if you have cygwin installed in the Windows Box, or using UNIX Shell then
Issue bash#which java
This will tell you whether java is in your classpath or NOT.
If you have set the environment variables (JAVA_HOME and PATH) under user variables, command prompt (run as administrator) will not identify java. For that you need to set environment variables under system variables.
Try this:
System variables:
PATH = /bin folder of your jdk install
https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-microsoft-windows-platforms.htm
Just some extra information for people that have still problems,
instead of editing the path variable of java, delete that part of the path(only the java!!)
and make a new variable pointing tpo the jdk/jre.
this seemed to work for me.

Error: picked up java_options: -Djava.net.preferIPv4Stack=true

I get this error when doing anything in cmd involving Ionic and Android, e.g. Ionic build Android, or Ionic emulate Android etc... What does the error mean, is it important, and how do I fix it?
I'm pretty sure the _JAVA_OPTIONS variable is tucked in your environment settings, it is shown nowhere else. To remedy this,
Press the Windows key and the Pause/Break key simultaneously
A window should popup, click on "Advanced system settings"
Click on "Environment Variables"
Check System Variables.
Delete the _JAVA_OPTIONS entry.
This "error" will happen if the variables JAVA_TOOL_OPTIONS or _JAVA_OPTIONS are set. I don't believe it is or should be of much concern to anything. As long as the application runs fine I see no real issue. So no, it is not very important, and seeing as the application was still built (and is likely working normally), I don't see a reason to try and correct it.'
Additionally if you do have errors within the application where this is the root cause, this might be of some help.
Relevant/important post from the thread:
A quick Google search indicates that this is output from the Java
virtual machine upon realizing that certain environment variables,
JAVA_TOOL_OPTIONS and JAVA_OPTIONS have been set.
http://www.nbl.fi/~nbl97/java/tuning/troubles/
These variables might be introduced in your Eclipse launch
configuration. More likely, they may have been set in your
workstation's environment by something you've recently installed.
On Windows XP, you can access the environment variables by right
clicking on "My Computer", selecting "Properties", switch to the
"Advanced" tab and click "Environment Variables". In that window, you
should be able to see if the environment variable has been set up.
Alternatively, you can open a command prompt and type "SET" to see
what environment variables have been set.

Setting environment variable permanently from java

Using Java,
How can I add environment variable permanently to the existing env variables.
so that when I do a restart operation for windows or Linux, this environment variable is still there.
You might want to take a look at this.
In Windows you can set a Path Variable from command line so it should do the trick.
I realize this is only applicable to Windows.
Not in any cross platform sort of way. In Linux, these are typically controlled via shell init scripts. You would have to edit one of those (which one depends on the user, system, and shell type). In Windows, this is controlled via system configuration (i'd imagine there are some windows specific APIs to modify those).
coppy the path of jdk upto C:\Program Files\Java\jdk1.6.0\bin from program and past in user variables and put ;.; at the end and give name .
and in system variables click on new and enter the name and past the path....and save ...
go to command prompt
..
to check current paths >echo %path%
to set path >set path="C:\Program Files\Java\jdk1.6.0\bin" enter ok now check and run java program
Environment variables are platform specific. Windows stores them in Registry.
*In the registry the User environment variables are stored at
HKEY_CURRENT_USER\Environment
and the System environment variables are stored at
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment
(from http://demins.blogspot.co.il/2007/10/where-does-windows-xp-store-evrironment.html)*
There are a lot of ways to access windows registry from java. You can for example execute command line using utility named reg that has a reach command line. You can also use one of interoparability APIs like JaWin, Jinterop, Jintegra. You can also refer to my solution explained here.
On linux you can use command line like export MYVAR=myvalue. I mean execute this command line from java using Runtime.exec() or ProcessBuilder. The problem is that this variable will not become really persistent. It will be visiable for all users until the computers is restarted. To make it really persistent you have to modify user login script (e.g. bashrc file for most linux systems if users's default shell is bash).

Script to Change JAVA_HOME System Variable in Windows

I do most of my work against JDK 1.5 - but occasionally I have to change to 1.6. it is a bit painful to have to manually go and change my 'JAVA_HOME' system variable whenever I need to work on a project specific to one or the other (and no, Eclipse doesn't play well in these scenarios - trust me...I've tried.)
I'm looking for a registry script or windows shell script or for that matter any means by which I can "toggle" this system variable with something that is easy to run.
I've messed with the 'set' command, but that only sets the variable for that particular command instance - not globally.
Thanks in advance.
EDIT #1:
Points of advise:
Use the JAVA_HOME variable in your path variable as well, that way you only have to change the JAVA_HOME (which is used in many projects anyways [maven, ant, etc])
Write the command into a couple batch scripts for easy use
When you make the change the windows command session will not reflect it right away. You must close and reopen it.
You could use setx for that purpose
Like so:
setx /M JAVA_HOME "C:\Program Files (x86)\Java\jdk1.6.0_17"

Permanently removing a JAVA_TOOL_OPTIONS environment variable

I am trying to run jake on OS X 10.6.4 but get the message Narwhal on Rhino requires Java 1.5 or higher. You have JAVA_TOOL_OPTIONS:.-Xmx512m. This is left over from a previous project where someone told me to set it to get Flash to export without dying.
I have java 1.6 installed. The JAVA_TOOL_OPTIONS seems to be the issue. I removed it using unset JAVA_TOOL_OPTIONS. This worked until I reopened Terminal. The JAVA_TOOL_OPTIONS environment variable comes back.
Any ideas on how I can permanently get rid of this?
You probably set it in the .bashrc or .profile file in your homedirectory, remove it from there and you should be fine when you start a new terminal.
It seems like you have that variable in your environment. All you need to do is to remove it from env:
Just write unset JAVA_TOOL_OPTIONS in your terminal.
Set that line in the ~/.bashrc file to be sure that it will not abuse you next time you run console.

Categories

Resources