Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

-classpath command revisited

 
carl summerfield
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
carl summerfield
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic