Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change java path

Status
Not open for further replies.

skarosi

Programmer
Jan 25, 2004
140
GR
Dear all,
I have been using java for some time now, but i was always used it within an editor (such as JCreator). Now though i have to make a programm that runs directly from dos mode, and so i need to change a path on the compiler, so it can compile and run in every directory.
can u help me a bit on this?
thank you
 
set CLASSPATH=%CLASSPATH%;C:\where\your\class\is

--------------------------------------------------
Free Database Connection Pooling Software
 
is it on classpath or on path?
i changed the classpath and it doesnt work
 
Are you talking about adding your own java class to be available to run from any directory or the actual compiler/runtime ? Your question is not overly clear.

To add the compiler and runtime exectuable to the OS's bin /exe search path:

set JAVA_HOME=C:\where\your\java_home\is
set PATH=%PATH%;%JAVA_HOME%\bin

--------------------------------------------------
Free Database Connection Pooling Software
 
i want to run my java programs using dos mode, from the directory they are in, and not only from the java home dir.
i think your second post is what i want.
where do i change these?
thanks
 
In the dos prompt, or in the environment variables tab of the System settings in Control Panel.

--------------------------------------------------
Free Database Connection Pooling Software
 
On the enviromental variables i have 2 paths, one called "classpath" and one "Path", seems both to b about java. which should i change?
sorry for the trouble,

Thanks
 
sorry to bother u ppl, but i still cant get it right.
on the enviromental Variables i have:
user Variables:
JAVA_HOME : C:\where\java\dir\is

and on System Variables
classpath: %PATH%;%JAVA_HOME%\bin
path : =%PATH%;%JAVA_HOME%\bin

i entered it in both just in case.
sorry for the truble but i have never done this b4. i have always used jcreator to run my programms.
thanks
 
The path variable is set to allow the dos system to find the java compiler(javac) and JVM (java), and is %JAVA_HOME%\bin on my PC.

The classpath variable is set to allow the compiler and JVM to locate all the external classes which your code uses.

For example, if your code imports org.apache.log4j.Logger, which is contained in the log4j.jar file, the path to this jar needs to be part of your classpath. I never use the dos classpath variable, prefering to specify the classpath at command-line level using the -cp flag.

So to run code in com.tim.MyClass, which uses classes in the log4j.jar distributable, I do:-
Code:
java -cp C:\jakarta-log4j\dist\lib\log4j.jar com.tim.MyClass

DOS knows what the 'java' command is because %JAVA_HOME%\bin is on my MS-DOS path.
 
ok, fair enought, but how and where u set the line
%JAVA_HOME%\bin ?
 
I'm on Win2000 so this applies to that OS.

Right-mouse on the desktop 'My Computer' icon and click properties. Select the 'Advanced' tab and click the 'Environment Variables' button. In the 'System Variables' list, scroll down to locate the path entry and edit it to include the %JAVA_HOME%\bin path. This obviously assumes that JAVA_HOME is an existing variable in either the system variables or user variables.

This setting will take effect on subsequently opened DOS windows.

Tim
 
ok, i have no idea what i am doing wrong.
on the user variables i have
JAVA_HOME: the directory where java is installed

on the System Variable i have
Path: %JAVA_HOME%\bin

and still when i try to compile/run a java file it doesnt work.
I have XP pro so it should b the same, i suppose.
thanks for your help m8
 
i get this error:
'java' is not recognized as an operable program or batch file.
 
but that what i am doing, i think,
on the enviromenal settings:

on the user variables i have
JAVA_HOME: the directory where java is installed

on the System Variable i have
Path: %JAVA_HOME%\bin
 
Right, baby steps then.

Option 1 : set the variables on a single dos prompt - this is an easy way.

Open a DOS prompt.
cd C:\where\your\.java file is

set JAVA_HOME=C:\where\your\java_home\is
set PATH=%PATH%;%JAVA_HOME%\bin
set CLASSPATH=%CLASSPATH%;.

And go ...

--------------------------------------------------
Free Database Connection Pooling Software
 
that wasnt too dificult was it?
i am not sure why it didnt work with the enviromental Variables method but since we got it to work thats fine by me
thank you all
sedj, what do u mean by "And go ..."?
cheers
 
By "And go..." I meant "compile & run your programme".

BTW, note that this was the solution I posted in posts 2 & 4 of this post !

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top