我是Java新手。我想在命令行上運行Java單元測試,並最終從PHP腳本運行它。我的代碼片段如下無法從命令行運行Java單元測試代碼
package com.src.test;
import java.io.File;
import java.io.FileWriter;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.thoughtworks.selenium.Selenium;
public class First {
......
}
的完整路徑在Windows上面的文件是 D:\Users\XXX\workspace\SeleniumTest\bin\com\src\test
當我將目錄切換到bin並運行java com.src.test.First
我得到一個錯誤信息:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
at java.net.URLClassLoader$1.run(Unknown Source)
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)
... 6 more
我在做什麼錯?我嘗試了運行java com.src.test.First.class
,並且出現錯誤Error: Could not find or load main class com.src.test.First.class
如果找不到類,則必須將一些類添加到類路徑中。 –
[通過命令行運行Java代碼時出現問題]可能的重複(http://stackoverflow.com/questions/2752485/problem-running-java-code-through-command-line) –