SE450: Packages: The Classpath [6/47] Previous pageContentsNext page

The java interpreter looks for packages along its classpath.

Suppose types is in directory d:\se450\code\build\classes. Then we can run Hello at any time by typing:

> java -classpath d:\se450\code\build\classes types.simplePackage.Main

or

> set classpath="%classpath%;d:\se450\code\build\classes"
> java types.simplePackage.Main

Note that java will ignore classes in the current directory unless . is in the classpath. If you are in a directory with Main.class and java replies

> java Main
Exception in thread "main" java.lang.NoClassDefFoundError: Main

try:

> java -classpath . Main

In windows, you can set your classpath variable permanently by adding a line at the end of c:\autoexec.bat and restarting your computer. For example:

set classpath=".;d:\se450\lib\ant.jar;%classpath%"

If DOS gives you the error "Out of environment space", then apply the solution found here: http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q230205&

In win2k, NT, XP you can also use, for example:

start |
  settings |
    control panel |
      system |
        advanced |
          environment variables |
            new | (or modify)
              Variable Name: classpath
              Variable Value: .;d:\se450\lib\ant.jar;(whatever was there before)

Previous pageContentsNext page