aspose file tools*
The moose likes Beginning Java and the fly likes -classpath command revisited Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "-classpath command revisited" Watch "-classpath command revisited" New topic
Author

-classpath command revisited

carl summerfield
Greenhorn

Joined: Aug 06, 2007
Posts: 6
This message is a rephrasing of a one posted by me several days past. I am a bit smarter about Java's lay of the land, but still am not getting the -classpath thing. Hopefully a better description, and some examples will better illuminate my quandary. Your suggestions have been appreciated.

My operating system is Windows2000, Professional edition

The javac.exe file is located here, C:\jdk1.6.0\bin
a HelloWorldApp.java is located on a different drive at D:\javasrc

The intent is to compile from the javasrc directory, what is the matter with these statements? How does the source file �communicate with the compiler when the compiler is on a different drive? As I understand, using -classpath, no environmental variables need to be set.

D:\javac HelloWorldApp.java

D:\javac -classpath D:\javasrc HelloWorldApp.java

D:\javac -classpath = D:\javasrc HelloWorldApp.java

D:\javac -classpath=D:\javasrc HelloWorldApp.java

D:\javac -classpath D:\javasrc\HelloWorldApp.java

The result of my attempts is
'javac' not recognizes as an external or internal command, operable program or batch file

Can compile and run if the HelloWorldApp.java file is executed within the bin directory.

Thanks, carl
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by carl summerfield:
...How does the source file �communicate with the compiler when the compiler is on a different drive? As I understand, using -classpath, no environmental variables need to be set... The result of my attempts is
'javac' not recognizes as an external or internal command, operable program or batch file

Can compile and run if the HelloWorldApp.java file is executed within the bin directory...

There are 2 different variables to consider: PATH and CLASSPATH.

The PATH variable is what allows your system find the Java executables (for example, java and javac) from different directories. If you don't set a system (environment) PATH to include Java's location, then you will need to include the complete path whenever you execute Java. For example...

> C:\Program Files\Java\jdk1.6.0_<version>\bin\javac MyFile.java

Setting a system PATH to include the Java bin directory is a Good Idea, because then "java" and "javac" will be able to execute from any directory, and you can just type...

> javac MyFile.java

As you've found, executing from the bin directory will also work, because the Java executables are already there, so no additional path information is needed. However, this is a Bad Idea, because then your own files get mixed in with the Java installation, and that's asking for trouble.

See Sun's Installation Instructions for Windows for details on setting the PATH.

The CLASSPATH variable is entirely different. This is what allows Java to find Java class files (other than what's included in the standard Java API). If you don't have a CLASSPATH, then the default is for Java to look in the current directory. Setting a system CLASSPATH is a questionable idea, and generally not needed when you're starting.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
carl summerfield
Greenhorn

Joined: Aug 06, 2007
Posts: 6
Marc,

Thanks for explaining this so well. Followed you instructions, and it worked.

carl


Originally posted by marc weber:

There are 2 different variables to consider: PATH and CLASSPATH.

The PATH variable is what allows your system find the Java executables (for example, java and javac) from different directories. If you don't set a system (environment) PATH to include Java's location, then you will need to include the complete path whenever you execute Java. For example...

> C:\Program Files\Java\jdk1.6.0_<version>\bin\javac MyFile.java

Setting a system PATH to include the Java bin directory is a Good Idea, because then "java" and "javac" will be able to execute from any directory, and you can just type...

> javac MyFile.java

As you've found, executing from the bin directory will also work, because the Java executables are already there, so no additional path information is needed. However, this is a Bad Idea, because then your own files get mixed in with the Java installation, and that's asking for trouble.

See Sun's Installation Instructions for Windows for details on setting the PATH.

The CLASSPATH variable is entirely different. This is what allows Java to find Java class files (other than what's included in the standard Java API). If you don't have a CLASSPATH, then the default is for Java to look in the current directory. Setting a system CLASSPATH is a questionable idea, and generally not needed when you're starting.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: -classpath command revisited