Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-04-2007, 07:28 PM   PM User | #1
starsiege2005
New Coder

 
Join Date: Apr 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
starsiege2005 is an unknown quantity at this point
Unhappy How do i set the java classpath(environment variable) in vista. help

Hi
Im studying java and i had it installed on my machine. It had xp and i knew how to set the class path on that. But now i upgraded to vista and when i set the classpath its not working....i mean i cant run any java from the command line...how do i set the class path properly? what should i enter in the environment variable? can anyone tell me exactly what to enter and where to enter?

Thanks heaps

my java directory (where i installed it) is

C:\Program Files\Java\jdk1.6.0_01\bin

thanks

also as an added precaution(if the vista path thing fails); can anyone tell me how to use the "java -cp"....i tried it but it gave me a list of options and im confused...how can i make my current directory the java path? how can i run a jar command..or compile things?

PS: aww also when i tried that the java programs on my eclipse stopped working....i have this message "cannot find main class program will exit"

java.lang.NoClassDefFoundError: BarViewer
Exception in thread "main"

BUT they were all working perfectly till i tried this!!!
the classes are visible in the project space too!!...why is this happening?

Last edited by starsiege2005; 05-04-2007 at 07:43 PM..
starsiege2005 is offline   Reply With Quote
Old 05-04-2007, 07:54 PM   PM User | #2
starsiege2005
New Coder

 
Join Date: Apr 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
starsiege2005 is an unknown quantity at this point
Unhappy

OH i have got it working

DAMN!!!! I MISSED A SEMICOLON!!!! SHOOT ME!!!!!!!!!!


well BUT still i do not get the eclipse programs in my project to work.... why do i keep on getting that error?


PS: PHEW I SORTED IT OUT
Its all ok now

Thanks folks

Last edited by starsiege2005; 05-04-2007 at 07:58 PM..
starsiege2005 is offline   Reply With Quote
Old 05-05-2007, 05:21 PM   PM User | #3
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
Glad we could help!
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline   Reply With Quote
Old 05-08-2007, 03:01 PM   PM User | #4
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
i dont think the CLASSPATH environment variable should ever be used.

You should only need the PATH environment variable to point to your jdk bin directory. (careful, in vista if you use setx it will make a new user environment variable instead of modifiy the system one, presumably you have to run command prompt with elevation (right click, run as administrator) in order to change the system path.)

-cp or -classpath takes a list of directories and jar files to search for your classes in. On windows it is separated by semicolons, on unix it is separated by colons. So for example if you had myjar.jar that contained some class files, and you also wanted to run class files from in the current directory (if your jar was a library and the current directory was your program or whatever) you could use

java -cp .;myjar.jar myprogram

I don't know how you managed to break eclipse
__________________
My tech/code blog
ghell is offline   Reply With Quote
Old 05-17-2007, 09:52 PM   PM User | #5
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
ghell...sorry to be a pain...but you actually need to use the CLASSPATH variable...and it should at the least contain the following value ".;"

Yeah, a dot and a semi-colon....why you might ask?...here is a simple answer.

The dot instructs the javac command to look for class definitions in the same directory of your file...before looking else where (JAVA_HOME). This means that if you have packages in your project...javac won't have problems compiling your files because it will start looking there first...and obviously...speed up the whole process of compilations.

Therefore...I would recommend the following setup

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_01;
PATH=%JAVA_HOME%\bin;%PATH%;
CLASS_PATH=.;

Cheers,
Ess
ess is offline   Reply With Quote
Old 06-24-2007, 12:05 PM   PM User | #6
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
As this was just linked to in another thread, I should probably reply in this thread as more people will be reading it now.

ess, sorry to be a pain, but you actually don't need it. The classpath flag defaults to "." and if you want to add extra things to it you can just use -cp .;some.jar (or -cp .:some.jar on unix). If you try and just use -cp some.jar then it obviously won't be able to search in the current directory, but the fact that you just missed . from the classpath flag, so are running it with the wrong command, does not mean that a CLASSPATH environment variable is needed.
__________________
My tech/code blog
ghell is offline   Reply With Quote
Old 11-08-2007, 05:37 PM   PM User | #7
eeelk
New to the CF scene

 
Join Date: Nov 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
eeelk is an unknown quantity at this point
I'm having a similar issue, and I'm stumped.

In windows XP, the following runs the target java application:

C:\Ptolemy\ptII> java -cp . ptolemy.vergil.VergilApplication


In windows vista (all else aside, everything is set up correctly), it does not, I get a

java.lang.NoClassDefFoundError

I've tried everything I can think of to specify the classpath, to no avail. Using -classpath doesn't work. using -cp "<exact path>" doesn't work. Always the same error. I've tried running the shell as admin, nothing. I've modified the system classpath to include <.>, tried dropping the -cp tag, etc...

Any suggestions would really help me out, thank you.

-Eeelk
eeelk is offline   Reply With Quote
Old 11-25-2007, 01:52 AM   PM User | #8
Crul
New to the CF scene

 
Join Date: Nov 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Crul is an unknown quantity at this point
Hi

I didn't want to create a new thread as I am having a CLASSPATH problem in vista as well. I'm trying to set it up so that I can compile my java program but it doesn't seem to work.

My javac is in the folder C:\Program Files\Java\jdk1.6.0_03\bin

and currently my CLASSPATH looks like

.;C:\Program Files\Java\jdk1.6.0_03\bin\;

I've tried various variations of this to make it work but nothing seems to be working. I get the following error when I type javac into the command line

'javac' is not recognized as an internal or external command,
operable program or batch file.

If somebody could help me out I would greatly appreciate it.

Thanks
Crul is offline   Reply With Quote
Old 11-25-2007, 02:34 AM   PM User | #9
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
the path to the jdk bin directory goes in your PATH environment variable not your CLASSPATH.

PATH is where the system looks for exes (like javac.exe)
CLASSPATH is where java looks for .class files (inside directories and jar files you specify)
__________________
My tech/code blog
ghell is offline   Reply With Quote
Old 11-25-2007, 03:12 AM   PM User | #10
Crul
New to the CF scene

 
Join Date: Nov 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Crul is an unknown quantity at this point
Thanks for the reply, it works now.

Much appreciated
Crul is offline   Reply With Quote
Old 09-03-2008, 10:28 AM   PM User | #11
Jwin
New to the CF scene

 
Join Date: Sep 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Jwin is an unknown quantity at this point
CLASS PATH environment variable

I to had the issue where certain JAVA programs would not work at all in Vista. My environment variable for classpath looked as follows

CLASSPATH .;C:\Program Files\Java\jdk1.6.0_03\bin

I removed the .; and now everything works fine but I am curious as to where these characters came from and why reomving them got everything working. I read the debates in this thread but it sounds like the characters might have a useful meaning even though I had to delete them to get my system working. If they are meaningful then what other change could I try to keep my system working.

Thanks
Jwin
Jwin is offline   Reply With Quote
Old 09-03-2008, 11:03 AM   PM User | #12
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
On Windows, a semicolon separates multiple directories. On unix, its a colon.

. means "this directory" (.. means "this directory's parent")

.;C:\Program Files\Java\jdk1.6.0_03\bin means "this directory and C:\Pro..._03\bin"

If you remove the "." from the list, it will stop looking for class files in your current directory.

If you did not enclose it in quotes, your problem was probably caused by it splitting at the first space and making your classpath ".;C:\Program", in which C:\Program does not exist.

Your "CLASSPATH" should always contain . (for any project in which you are working on more than 1 java file). Your "CLASSPATH" should not contain "C:\Program Files\Java\jdk1.6.0_03\bin" but if you add it to your "PATH", then you can just type
Code:
java.exe foo
rather than having to type
Code:
C:\Program Files\Java\jdk1.6.0_03\bin\java.exe foo
every time. (the .exe is optional on Windows)

PATH is where your operating system looks for executable files (.exe on Windows). CLASSPATH is just a Java environment variable and is just where Java looks for class files. CLASSPATH can contain directories (that contain class files) or JARs. PATH will usually be used to point to common directories that hold exes, dlls, etc. For example, C:\Windows\System32 is probably where you have ipconfig.exe, and is why you can just type "ipconfig" to use it, rather than having to type "C:\Windows\System32\ipconfig(.exe)"


So, if your current PATH is "foo" then you should make it "foo;C:\Program Files\Java\jdk1.6.0_03\bin"
and your CLASSPATH should be "." unless you need specific other directories or JARs. Usually you just modify your global CLASSPATH if you want to do something like install the mysql driver jar into one directory on your computer and then give every java application on the entire machine access to it. Otherwise, you would just put the jar file with the rest of your files and run with something like
Code:
java -classpath ".;mysql.jar" foo
In this example, the quote marks are not necessary. If the jar file were called "my sql.jar" then you would use ".;my sql.jar" so that it didn't just look for "." and a directory called "my".
__________________
My tech/code blog

Last edited by ghell; 09-03-2008 at 11:07 AM..
ghell is offline   Reply With Quote
Old 10-17-2011, 07:23 PM   PM User | #13
a2ztechguide
New to the CF scene

 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
a2ztechguide is an unknown quantity at this point
For windows users (in Vista / Windows 7), you can set the CLASSPATH permanently via "Control Panel" > "System" > "Advanced system settings". Switch to "Advanced" tab > "Environment variables" and choose "System Variables" (for all users) or "User Variables" (for this login user only):

1) (RECOMMENDED) Delete CLASSPATH from both System and User variables if exists.

2) To modify the existing CLASSPATH, select variable "CLASSPATH" and Choose "Edit". In variable "Value", provide the directories and jar-files, separated by semi-colon ';'. Make sure that the current directory '.' is included as the first entry.

3) To create CLASSPATH, choose "New". In variable "Name", enter "CLASSPATH" and in variable "Value", provide the directories and jar-files, separated by semi-colon ';'. Make sure that the current directory '.' is included as the first entry.

For full article refer to this link

http://www.a2ztechguide.com/2011/10/...-javahome.html
a2ztechguide is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:51 AM.


Advertisement
Log in to turn off these ads.