Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set a class path?

 
Jenny raj
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear ranchers

could u please help me setting up the class path for my java files?
i have just installed JSDK1.5 version.
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you compile use javac -classpath ...

When you execute use java -classpath ...

Do not use the CLASSPATH environment variable. Use a script to compile/run with -classpath.
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm also a beginner and this is a real bone of contention for me!!
my jdk bin files are in c:\program files\java\jdk\bin
i usually have to cd down to this dir to javac or java any of my programs.

however when i try from C:\>
javac -classpath c:\program files\java\jdk\bin MyApp.java

java -classpath c:\program files\java\jdk\bin MyApp


...it never works!!!

(p.s MyApp.java is not in a named pakage)
[ September 27, 2005: Message edited by: kwame Iwegbue ]
 
Norm Radder
Ranch Hand
Posts: 732
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>..it never works!!!
Does it give an error message?
What is that message?
With the contents of the error message someone might be able to help.

Include the commandline that you typed also.
 
Annie Smith
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In the Environment Variables, setting the path variable to the bin of the jdk, should make things work, right?

Correct if I am wrong.

Cheers,
Ram.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your program has no package statement, going to the directory where the class file lives should do the trick. See if THIS helps. Let me know if it isn't clear and I'll try to fix it up. Thanks!
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Incorrect:

javac -classpath c:\program files\java\jdk\bin MyApp.java

You need to put java in your PATH environment variable, preferably near the start. That is the standard place to allow any executable program to be found and not specific to Java of course.

The -classpath is strictly for jars and classes. It think you have confused PATH and -classpath.
[ September 28, 2005: Message edited by: Rick O'Shay ]
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See our FAQ: How To Set the Classpath
[ September 28, 2005: Message edited by: Joel McNary ]
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sadly, the FAQ needs serious rework and simplification including a de-emphasis of the system dependent CLASSPATH variable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic