0

I'm having a project in IntelljiIdea, and it's a simple program for visiting some URLs, using selenium. I got this working just fine in python and C# using both Chromium and Firefox, but not in Java.

Here are the libraries from Idea

enter image description here

I'm using the selenium-server-standalone.jar, latest, from http://selenium-release.storage.googleapis.com/index.html?path=2.48/, same as common-codecs, I'm using the standalone jar file, and for selenium-chrome-driver and selenium-firefox-driver, I'm using maven. Firefox works in the IDE, but once I run the jar (artifact), I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
    at com.myprogram.controller.VisitController.visit(VisitController.java:109)
    at com.myprogram.controller.VisitController.visit_websites(VisitController.java:73)
    at com.myprogram.controller.VisitController.run(VisitController.java:45)
    at com.myprogram.controller.Controller.visit(Controller.java:127)
    at com.myprogram.controller.Controller.run(Controller.java:280)
    at com.myprogram.Main.main(Main.java:11)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 6 more

Only Firefox is working, starting it from the IDE. Chrome (chromium), doesn't work from IDE, and not working started from command line either, same as Firefox, if I start the program with java -jar my_program.jar

I'm on archbang x64, using the selenium version from screenshots, and java version 1.7.0_91

Any suggestions are appreciated.

UPDATE I have set selenium jar files to be a dependencies in my artifact, so selenium should be included in my_program.jar. In other words, if I run it like this java -cp selenium-server-standalone-2.48.2.jar -jar my_program.jar will give me the same error.

user1812076
  • 269
  • 5
  • 21

1 Answers1

0

If you want to run selenium from command line, you should either add selenium-server-standalone on the classpath of your jar (e.g. using -cp option, example here), or get maven to build jar with selenium-server-standalone included in your jar. Probably the easiest way to achieve that is to get jar with all dependencies, as explained here, although in that case you are duplicating some dependencies, since selenium-server-standalone also has all of its dependencies (thus jar is bigger).

Community
  • 1
  • 1
timbre timbre
  • 12,648
  • 10
  • 46
  • 77
  • Updated the question. – user1812076 Dec 30 '15 at 19:43
  • @user1812076 `-cp` means class path, not just class name. It won't find it, you need to either put it in the classpath already known to java (you can check you current classpath by running `echo ${CLASSPATH}`, although it may not be set. Or you need to provide a full path to your jar, e.g. `java -cp /some/path/where/selenium-server-standalone/sits/ ...` – timbre timbre Dec 30 '15 at 21:05