1. Specifying the -classpath argument in the command line
C:\users\LavanniM>java -classpath "C:\users\LavanniM\confucius" HelloWorld
Hello World!
C:\users\LavanniM>
2. Setting the CLASSPATH environment variable
C:\users\LavanniM>set CLASSPATH=C:\users\LavanniM\confucius
C:\users\LavanniM>java HelloWorld
Hello World!
C:\users\LavanniM>
1 comment:
Actually in Windows, there is a third way - the SET command that you mentioned only sets it in the current CMD session. But to set it at the user profile level, go to My Computer > Properties > Advanced > Environment Variables.
You should see a CLASSPATH already there as when you installed the JDK, the installer created a default CLASSPATH variable and initialized it to "sensible" defaults. You can either append to this CLASSPATH variable or if it isn't there (i.e. you merely got a JRE from some place and placed it in a directory), create one and then this will take effect everytime you login to that machine.
Of course an ideal way would be to get these environment variables from some standardized lookup location like an LDAP server... just a thought.
Post a Comment