package cn.togeek.job; public class Test { public static void main(String[] args) throws Exception { System.out.println("Hello,world!"); } }
1 javac Test.java
运行正常
接着运行
java Test
会报错
1 at java.lang.ClassLoader.defineClass1(Native Method) 2 at java.lang.ClassLoader.defineClass(Unknown Source) 3 at java.security.SecureClassLoader.defineClass(Unknown Source) 4 at java.net.URLClassLoader.defineClass(Unknown Source) 5 at java.net.URLClassLoader.access$100(Unknown Source) 6 at java.net.URLClassLoader$1.run(Unknown Source) 7 at java.net.URLClassLoader$1.run(Unknown Source) 8 at java.security.AccessController.doPrivileged(Native Method) 9 at java.net.URLClassLoader.findClass(Unknown Source) 10 at java.lang.ClassLoader.loadClass(Unknown Source) 11 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 12 at java.lang.ClassLoader.loadClass(Unknown Source) 13 at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
这个时候:
../../.. 然后运行,OK好了
这么运行也是OK的 E:\src>java -cp ./main/java/ cn.togeek.job.Test Hello,world! 在
E:\src>java -cp E:/src/main/java/ cn.togeek.job.Test Hello,world! 这样在所有文件夹下都可以运行了!
时间: 2024-10-09 10:40:43