Why NetBeans' environment variable does not confirm to the system's setting? - java

I have set JAVA_HOME environment variable in .bashrc like this:
export JAVA_HOME='/opt/Oracle/jdk1.7.0_25'
And I am sure that it's properly set:
$ echo $JAVA_HOME
/opt/Oracle/jdk1.7.0_25
But when I am using NetBeans to start my Google App Engine server, it says:
...
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-7-openjdk-amd64/jre"
Why it is changed?

The env variable is set in any bash window you might open up, but it is not set any other way. It seems you will have to resort to desperate measures to get this environment variable set up, which entails setting the variable from the command line and then starting NetBeans from the command line. I can't think of any other way.

Related

Windows environment variable resolution error

I am trying to put the JAVA JDK path into the Windows PATH environment variable.
I changed/inserted the appropriate variables and got the command javac to be working yesterday, but when I tried the same thing today, I am getting the command not recognized error.
Here are the values of the relevant variables (on a fresh cmd instance):
>> echo %JAVA_HOME%
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_101
>> echo %PATH%
C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;%JAVA_HOME%\bin;C:\Users\anmol\AppData\Local\Programs\Python\Python35\Scripts\;C:\Users\anmol\AppData\Local\Programs\Python\Python35\;C:\Users\anmol\AppData\Local\Programs\Python\Launcher\
I tried to avoid the spaces present in 'Program Files' by writing JAVA_HOME=C:\Progra~1\Java\jdk1.8.0_101, but the error persisted.
Also, if I open a cmd and type set path=%JAVA_HOME%\bin;%path% and then in the same session type javac, it is recognized correctly.
Can anyone tell what is going on and how to set the PATH correctly?
You have modified PATH with the set command, which applies the changes to the current terminal. To make it a persistent system wide setting, use setx instead.
You'll need both, PATH and JAVA_HOME in the system environment.
Note that ` does not modify the current terminal's environment settings:
NOTE: 1) SETX writes variables to the master environment in the registry.
2) On a local system, variables created or modified by this tool
will be available in future command windows but not in the
current CMD.exe command window.
What has happened in your case? You have set the PATH environment variable at a time where JAVA_HOME was not known yet. In that case, %JAVA_HOME% becomes part of PATH literally. The following example demonstrates that:
C:\>set X=%A%
C:\>set A=something
C:\>set X
X=%A%
C:\>set B=something
C:\>set X=%B%
C:\>set X
X=something
To fix it, set JAVA_HOME using setx, close the terminal and open a new one. Then use setx to set PATH, close the terminal and open a new one.
or
set JAVA_HOME using setx, set JAVA_HOME using set to update the console. Then use setx to set PATH, close the terminal and open a new one.

Not able to set JAVA_HOME variable in ubuntu 14.04 on manual installation

I've downloaded java jdk1.8.0.7.tar.gz file from the official website and unzipped it into my home directory. Now to set the $JAVA_HOME variable I used the follwing commands command nano .bashrc and then appending export $JAVA_HOME=/home/shivam/Java/jdk1.8.0.7 at the end of the file . But whenever I run the command sudo $CATALINA_HOME/bin/startup.sh I get an error message saying
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
I don't understand why it is unable to find the java path though I've installed tomcat and set its home variable the this way, which worked.
I wan't to install Java manually without using apt-get. Kindly guide .
You want to append the following to .bashrc:
JAVA_HOME=/home/shivam/Java/jdk1.8.0.7
Note the missing $ at the start.
Also remember that the file won't effect your current shell without sourceing it first.
Also, when running a command with sudo, you are running it as the root user, not as yourself. So the environment variable needs to be set for the root user, not yourself.
You can run sudo env | grep JAVA_HOME to see whether it is set for root.
Have you run .bashrc ?
source .bashrc
Try add the following 2 lines in your .bashrc file:
JAVA_HOME=/home/shivam/Java/jdk1.8.0.7/
export JAVA_HOME

Apache Ant installation Windows 7

When I do ant -version on command line, it says not recognized. Any ideas on how to fix? I'm trying to make a build.xml for a Java project.
You have set JAVA_HOME and ANT_HOME as User environment variable. The path you set is in System environment variable.
You can fix it by many ways. One way will be to define JAVA_HOME and ANT_HOME in System Environment setting.
Another way will be to modify PATH variable in user environment section.
Make sure your JAVA_HOME and ANT_HOME and PATH are set correctly.
ANT_HOME is used by the launcher script for finding the libraries.
JAVA_HOME is used by the launcher for finding the JDK/JRE to use. (JDK is recommended as some tasks require the java tools.) If not set, the launcher tries to find one via the %PATH% environment variable.
PATH is set for user convenience. With that set you can just start ant instead of always typing the/complete/path/to/your/ant/installation/bin/ant.
Set these variables correctly and open a new cmd window (don't use old cmd window, please open new window)
type echo %PATH% , should show java and ant
Open command window(cmd) and type
java -version
If this shows java version , this means java is in your path and working.
finally type ant -version

System.getenv() does not list all the environment variables

I have noticed that some of my environment variables are not being picked up by the JVM.
In my .bash_profile I defined the following:
IO_HOME='some_value'
export IO_HOME
and by doing in shell:
echo $IO_HOME
I get the correct result.
But neither System.getProperties() nor System.getenv() is showing this variable being set. I tried both Java 6 and Java 7.
Is there something I am missing?
Exporting environment to spawned processes is pretty stable; if System.getenv() is not including a variable then it is because it is not in the environment. A couple of things to check, both relating to how the process is started:
Are you starting the java process from an environment where the variable is exported? For example, if it is in your .bash_profile and you are executing the java program from a menu or desktop then you have to log out and log in after adding it in .bash_profile for your desktop to see the variable.
Is the variable explicitly removed from environment for the process? ProcessBuilder allows this, as do most of all APIs that spawn processes.
One thing to try is to start the process from command line shell, after ensuring the variable is exported in that shell.
From Windows, I recently saw some crazy behaviour where IntelliJ refused to show all env vars from System.getenv() after setting either user or system env vars. The trick was to launch IntelliJ from a DOS box. For Windows users: Maybe a reboot (or logoff/logon) will fix the issue.

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