Need help setting Java environment variables.

Permabanned
Joined
3 Aug 2009
Posts
1,397
Location
Manchester
Hi guys.

I was wondering if anyone could give me a quick walk through on how to setup my Java environment variables as I can't find any clear guides on Google.

Cheers
 
Depends what OS your running and what you mean by "environment variables"

I will assume you are running windows, and want to set the PATH and CLASSPATH so that you can write java, javac, javadoc, javap etc in the command line.

Go to system properties (control panel), then advanced system settings and there should be a button that says environment variables.

You then need to either edit/or create a new variable called PATH and add the java bin directory to this (usually C:\JDK1.5\bin), if there is already a PATH variable you can add to it by separating with a semi-colon. This basically tells the OS where to look when you type javac etc.

The CLASSPATH variable can be set in the same way BUT it is used to store packages and classes. I am not entirely sure but I think javac searches the current directory and the CLASSPATH when you import a package, so you can just put them in the directory you are working in.

If you have done this correctly type java -version in cmd prompt and you should see a printout telling you the current version of the jvm.

If you want to retrieve Environment variables in a program then search the java documentation on the SUN website as there are system methods to achieve this
e.g. System.getProperty("os.name")

Hopefully this has helped
 
You might also need to set the variable 'JAVA_HOME' to point at the dir containing your java installation. In Elston15's example, this would be 'C:\JDK1.5'.

Let us know what you're trying to do (i.e. why you need to set the env vars) and we can give you more specific help.
 
I want to set variables because I program I'm using wont load Java when it supposed to. Some one else said if I set variables it should solve it. :confused:
 
Try typing at a command prompt:

java -version

If you get a 'not found' type error, that means your PATH variable is not set correctly - do what Elston15 suggested to fix it - but be careful...do not overwrite the current value. Add your entry to the start or end, followed by a semi-colon.

If your software still doesn't work, try typing at a command prompt:
echo %JAVA_HOME%

This should display the dir your java is installed into. If not, set a variable called JAVA_HOME to the value of your java installation dir.

If you still have no joy, look in the installation dir of the application you are trying to run for log files which might help diagnose the problem.

Let us know how you get on.
 
Hi guys -

I've set all that, for example in System Variables I have -

PATH - C:\Program Files\Java\jre6\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static

CLASSPATH - C:\Program Files\Java\jre6\bin

JAVA_HOME - C:\Program Files\Java\jre6\bin

And the client I'm still trying to open wont run using Java. Is there anything I need to set in user variables?

Thanks a lot.
 
It's hard to really help more without knowing a bit more about the problem.

Is the program trying to run java or are you trying to run the program through the jvm?
Is it a JAR file or a CLASS file you are trying to run?

When you type java -version in cmd do you get an error or a jvm version?
If you don't get an error then your PATH is set correctly.

However looking at your reply there are several things to point out. Firstly the JRE (java Runtime Environment) and JDK (Java Developement Kit) are two different things. The jre is your bog standard java that everyone has.

The jdk contains tools used by people developing java programs, and contains the java compiler (depending on which jdk you get) and various other useful tools like javap and javadoc. You have linked the JRE in the PATH posted which means if the program is trying to find jconsole or another command it won't find it.

Secondly, your JAVA_HOME directory should be "C:\Program Files\Java\jre6" only, as deadfolk mentioned.

As deadfolk said, hopefully the documentation or error logs included in the program should shed some more light on the matter.
 
Back
Top Bottom