Note that there are some explanatory texts on larger screens.

plurals
  1. PONoClassDefFoundError in JavaFx with Command line Parameters with Selenium Code?
    primarykey
    data
    text
    <p>I'm trying to do a JavaFX Application that can receive command line parameters. I can receive the parameters. But I'm having problems when I instanciate the "A" class (from Main.java) that has Selenium (Testing/WebBrowser Automation Library) members inside.</p> <pre><code>// Main.java package myPackage; import java.util.Map; import javafx.application.Application; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage stage) { if (getParameters().getRaw().isEmpty() == false) { System.out.println("The application was called by Command Line."); Map&lt;String, String&gt; params = getParameters().getNamed(); System.out.println(params.get("a")); A myA = new A(); } else { System.out.println("The application was called executing the jar file."); A myA = new A(); } } public static void main(String[] args) { launch(args); } } </code></pre> <hr> <pre><code>// A.java package myPackage; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.chrome.ChromeDriver; public class A { ChromeDriver driver; A() { System.out.println("New A Instance."); System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe"); this.driver = new ChromeDriver(); } public boolean isElementPresent(By by) { try { this.driver.findElement(by); return true; } catch (NoSuchElementException ex) { return false; } } } </code></pre> <p><strong>But when I try to execute it with:</strong> <code>java -cp MyProject.jar myPackage.Main --a="value1"</code></p> <pre><code>The application was called by Command Line. value1 Exception in Application start method java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:367) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:305) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:894) at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56) at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158) at java.lang.Thread.run(Thread.java:744) Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/NoSuchElementException at myPackage.Main.start(Main.java:16) at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837) at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:331) at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:297) at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:294) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39) at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112) ... 1 more Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.NoSuchElementException at java.net.URLClassLoader$1.run(URLClassLoader.java:359) at java.net.URLClassLoader$1.run(URLClassLoader.java:348) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:347) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 12 more Exception running application myPackage.Main </code></pre> <p>As you can see, the app get the parameter and prints it (first and second line in this output above)...</p> <p>I read that line <code>NoClassDefFoundError: org/openqa/selenium/NoSuchElementException</code> but selenium library (2.37.0) is added, and the libs dependencies too. In Netbeans in the <code>Libraries &gt; Compile</code> tab</p> <p>If I run the application using Netbeans <code>Project properties &gt; run &gt; parameters</code> and inserting one parameter all is fine. The problem comes when I do the same by Command Line...</p> <p>I have tried a LOT of things... and I Can't Understand, why ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload