JAVA 运行包中的类

Java中的包是以目录的形式组织的,在java文件中如果指定了相应的包,相应的编译和运行命令如下:

编译:javac -d . Cat.java    或者   javac-d E:\haha Cat.java  

运行:java com.xmu.cs.Cat

 

如果不采用,则会出现D:\java\com\xmu\cs>java Cat

Exception in thread "main" java.lang.NoClassDefFoundError: Cat
Caused by: java.lang.ClassNotFoundException: Cat
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Cat.  Program will exit.
 

你可能感兴趣的:(java)