问题
java -jar selenium-server-2.1.0.jar -role rc -hub http://localhost:4444/grid/register -port 5555
2.8.2011 12:14:12 org.openqa.grid.selenium.GridLauncher main
INFO: Launching a selenium grid node
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONExceptio
n
at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:57)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
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)
... 1 more
回答1:
You need to use the selenium-server-standalone-2.X.Y.jar in order to get all the necessary libs. The selenium-server-2.X.Y.jar is only if you intend to manage your own classpath.
回答2:
I have the same problem. Things I've tried so far:
- Include the Selenium-2.3.0/libs folder in my classpath environment variable
- Include the Selenium-2.3.0/libs folder with a command line override "-classpath /path/libs/*"
- Add json.jar (with JSONException.class in org/json folder) to my jre's ext folder and made sure it's on the classpath
- Written my own MyTest.java class (code below), compiled it and run it without problems
import org.json.JSONException;
public class MyTest {
public static void main(String[] args) {
new JSONException("message");
}
}
So what's next?
回答3:
For ppl working on selenium and are new to selenium. Download latest Selenium Standalone Server jar file from http://docs.seleniumhq.org/download/ Right click on project--> Build Path-->Configure Build Path.. Here in Java Build Path section, goto Libraries tab and click on "Add External Jars" button Now, add the above jar file downloaded here.click Apply and then OK.
this resolved the issue for me.
回答4:
As nirvdrum mentioned, unless you want to manage your classpath I would recommend using the selenium standalone server
JAR file.
for the hub use:
java -jar selenium-server-standalone-2.3.0.jar -role hub
for a node on the same machine:
java -jar selnium-server-standalone-2.3.0.jar -role remotecontrol -hub http://localhost:4444/grid/register -port [XXXX]
(something other than 4444)
This is just to get your grid setup. In order for you to use run a test through the grid you would need to use a RemoteWebDriver
instance that references your hub. For example:
WebDriver driver = new RemoteWebDriver( new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox() );
来源:https://stackoverflow.com/questions/6910488/selenium-server-grid2-start-problem-noclassdeffounderror-exception