wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How do i set a/the classpath. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do i set a/the classpath." Watch "How do i set a/the classpath." New topic
Author

How do i set a/the classpath.

Jason Martin
Greenhorn

Joined: Jun 11, 2009
Posts: 8
I just finished doing the Head First HTML, XHTML, and CSS book and i also got the Head First Java 2nd edition book. i didnt have any trouble with the xhtml book but im having problems getting this java one to work. I think i have narrowed it down to not have the classpath set to the right folder/s. I have Java and the JDk installed to C:\Java\bin and the folder with my .java and .class files in C:\Users\....\Desktop\JavaWork . now i managed to get it 1 of the .java files i made from reading the HF book into a .class file by moving the folder into the Java folder. but that shouldnt be right either from what i have read on here + on the Java Sun website. Also im on 64bit vista if that makes any difference. Thanks in advance for the help!
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
Jason Martin wrote:I just finished doing the Head First HTML, XHTML, and CSS book and i also got the Head First Java 2nd edition book. i didnt have any trouble with the xhtml book but im having problems getting this java one to work. I think i have narrowed it down to not have the classpath set to the right folder/s. I have Java and the JDk installed to C:\Java\bin and the folder with my .java and .class files in C:\Users\....\Desktop\JavaWork . now i managed to get it 1 of the .java files i made from reading the HF book into a .class file by moving the folder into the Java folder. but that shouldnt be right either from what i have read on here + on the Java Sun website. Also im on 64bit vista if that makes any difference. Thanks in advance for the help!



first you don't have to set the classpath for your source files. in a dos window go to the directory which has your .java files run javac file.java I am guessing you don't have your files in a package?? next run your execute the class file accordingly java -cp . filename
Jason Martin
Greenhorn

Joined: Jun 11, 2009
Posts: 8
mk so i run CMD as an admin than set the directory to the javac file? and package such as inside a folder? and to run the .class file i have to type in java -cp(do i just type -cp in? or the C:\etc\etc than the actual file?) . HelloWorldApp ? first time trying to learn programing so sorry if i dont understand it all.
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
you can say java -cp . classname or you can put java -cp c:\whatever.classes classname the '.' refers to the current directory in which you are located so if you type cd .. at the dos prompt you will go up a directory if you type cd . then you stay in the same directory
Jason Martin
Greenhorn

Joined: Jun 11, 2009
Posts: 8
ok get an error when trying to compile it: ' javac ' is not recognized as an internal or external command, operable program or batch file.
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
you have to type set path=%PATH%;.;c:\java\bin 'enter'
Jason Martin
Greenhorn

Joined: Jun 11, 2009
Posts: 8
Adam LaFaye wrote:you have to type set path=%PATH%;.;c:\java\bin 'enter'

ah k that makes it work! /cheer 6 days of trying to fix this on my own and something as simple as that fixes it
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
recommend download eclipse ganymede and create java applications in it. then choose server runas applications it will do all the pathing for you
Jason Martin
Greenhorn

Joined: Jun 11, 2009
Posts: 8
Adam LaFaye wrote:you have to type set path=%PATH%;.;c:\java\bin 'enter'

ah k that makes it work! /cheer 6 days of trying to fix this on my own and something as simple as that fixes it
Hmm they should think about adding that to the Head First Java book or put it in a read me with the downloadable files for the book. Couldnt find it on Java's site either. they just say you need to change the path but dont tell you how to change it
Jason Martin
Greenhorn

Joined: Jun 11, 2009
Posts: 8
Adam LaFaye wrote:recommend download eclipse ganymede and create java applications in it. then choose server runas applications it will do all the pathing for you

:O where can i find it? also is it free? Iv got Adobe Creative Suite 4 btw if theres any programs in it that work with this.
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
free. just go to eclipse.org and download it. lots of tutorials available as well
Jason Martin
Greenhorn

Joined: Jun 11, 2009
Posts: 8
this one? Eclipse d/l
Edit: Prob a dif one since im on 64bit....
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
I believe that is what you want. I am using that version on Vista as well.
Jason Martin
Greenhorn

Joined: Jun 11, 2009
Posts: 8
kk. just wanted to make sure since it says 32bit. + i dont see a 64bit version any where
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do i set a/the classpath.
 
Similar Threads
Error in Servlet compilation
Question related to Classpath when using the java and javac commands.
Setting up JAVA
can't compile .java file
A pain in the ......Please help?