0

I'm a Java newbie. I have a Java application that runs perfectly in Eclipse. I have exported it as a jar file aaccording to the instruction found at http://www.vogella.com/tutorials/Eclipse/article.html#firstjavaexport.

However, when I run my application from the command line, I get an error message saying:

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

What am I doing wrong?

user1801060
  • 2,733
  • 6
  • 25
  • 44
  • 3
    http://stackoverflow.com/questions/11033603/how-to-create-a-jar-with-external-libraries-included-in-eclipse Basically you need to add your dependencies to the jar – diazazar Jan 31 '14 at 14:53
  • 1
    You don't have dependent jars like selenium or any other which you might have used in your code. – Husam Jan 31 '14 at 14:53
  • Or to classpath of runner. – Basilevs Jan 31 '14 at 14:53
  • @paul.cioroianu: Thanks a lot. But how do I create a launch configuration for a JUnit Test? All the ones I can see are only for Java applications. – user1801060 Jan 31 '14 at 15:22
  • I'd say that the biggest problem here is lack of vital knowledge; you don't know how to manage using Java outside of Eclipse, and so you don't know how to for example manage a classpath. – Gimby Jan 31 '14 at 15:25

2 Answers2

0

You need export your project like Runnable JAR file (File > export > Java / Runnable JAR file).

After this, you can execute via command line java -jar app.jar

0

Package the dependencies in your jar file or add the dependency to your classpath when running your app e.g. java -classpath /path/to/dependency.jar -jar myapp.jar

cmd
  • 11,622
  • 7
  • 51
  • 61