我已經在src下的包「first」下創建了eclipse中的類。 我會在日食中執行得很好。但是,當我試圖從命令提示符下運行,它會說錯誤:無法找到或加載主類CreatingThread
"Error: Could not find or load main class CreatingThread".
但是,當我相同的類複製出到其他文件夾,並刪除package first
它會正常工作。
我已經設置環境變量如下:
path %JAVA_HOME%\lib;C:\Program Files\Java\jre1.8.0_144\bin
classpath %JAVA_HOME%\lib\tools.jar;.;
而這些類
package first;
public class CreatingThread {
public static void main(String[] args) {
System.out.println(Thread.currentThread().getName());
System.out.println(Thread.currentThread().getPriority());
System.out.println(Thread.currentThread().getThreadGroup());
for(int i=0;i<=25;i++) {
System.out.println(Thread.currentThread().getName()+" "+i);
}
MyThread myThread= new MyThread();
myThread.setName("Child Thread");
myThread.getThreadGroup();
myThread.start();
System.out.println("Done");
}
}
二等
package first;
public class MyThread extends Thread {
@Override
public void run() {
for(int i=0;i<=25;i++){
System.out.println("child thread "+i);
}
}
}
什麼是通往CreatingThread.class的路徑? – Ouney
iin命令提示符我做了cd workspace \ corejava \ multithreadingrevision \ src \ first然後Javac * .java – spa
您需要使用'java -cp執行。 first.CreatingThread' –