java.lang.NoClassDefFoundError: org/openqa/selenium/remote/service/DriverService$Builder - eclipse

I am trying to create a TestNg Maven project in Eclipse for Selenium. Here is my code :
package Edureka_Case_Study_8th.Edureka_Case_Study_8th;
import org.testng.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class CaseStudy2 {
#Test
public void basicSetup() {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Sitesh\\Selenium\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.flipkart.com/ ");
}
}
When I try to run it, I get the following error:
[RemoteTestNG] detected TestNG version 7.3.0
FAILED: basicSetup
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/service/DriverService$Builder
at Edureka_Case_Study_8th.Edureka_Case_Study_8th.CaseStudy2.basicSetup(CaseStudy2.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.util.ArrayList.forEach(Unknown Source)
at org.testng.TestRunner.privateRun(TestRunner.java:764)
at org.testng.TestRunner.run(TestRunner.java:585)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
at org.testng.SuiteRunner.run(SuiteRunner.java:286)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.ClassNotFoundException:
org.openqa.selenium.remote.service.DriverService$Builder
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)
... 29 more
Can anybody please come up with a suggestion / solution ?
Artifacts used :
Eclipse - Version: 2020-06 (4.16.0) , Selenium - v3.141.59

Its look like issue is with Selenium Libraries. Please add all selenium jars. Follow below:
Download Selenium Client & WebDriver Language Bindings for Java from (Make sure you are downloading as per your system configuration) https://www.selenium.dev/downloads/
Unzip the file.
Open your project > Right click > Build Path > Configure Built Path > Libraries > Add External Jars
Select all jars present inside above unzipped folder ( Make sure you add libs also).
Also insure Java is installed and path for JDK is pointed under execution environment.
Go to Build Path > Configure Built Path > Libraries.
Open JRE System Libraries
And if by default selected environment is not pointing to JDK. Select Alternate JRE.
Click on Installed JREs and browse to JDK folder select.
Note : Using Same Code and above mentioned SetUp I am able to run your script.

Related

i m using a POS Tagger with this code

I'm using a POS Tagger with eclipse, here is code
package tagger;
import java.io.*;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
public class ab_web
{
public static void main(String[] args)
{
MaxentTagger tagger = new MaxentTagger( " D:\\tagger\\english-bidirectional-distsim.tagger");
String sample = "i go to school by bus";
String tagged = tagger.tagString(sample);
System.out.println(tagged);
}
}
but I am having exceptions
Exception in thread "main" java.lang.UnsupportedClassVersionError: edu/stanford/nlp/tagger/maxent/MaxentTagger : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at tagger.ab_web.main(ab_web.java:8)
kindly tell me any solution for this?
Unsupported major.minor version 52.0 means that the MaxentTagger class you are trying to use was compiled using Java 8 but you are trying to run it using an earlier version of Java.
Look in the Eclipse 'Run > Run Configurations' menu and find your program. Make sure the 'Java Runtime Environment' is set to use Java 8 (or JavaSE-1.8').
If no Java 8 is listed in the Run Configuration you may have to tell Eclipse about the location of a Java 8 JRE. Open the Eclipse Preferences and go to 'Java > Installed JREs' to do this.
You must be running Eclipse Mars or Luna to get full Java 8 support.

Error to connect database in Eclipse JDBC ODBC,

I'm looking for resolve problem with eclipse, im trying to connect to MySQL via ODBC im using java 1.7, and the same code in NetBeans, and Eclipse,
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Gtable","root","");
In NetBeans it works fine but in Eclipse returns
Exception in thread "main" java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at testdb2.testd.main(testd.java:11)
How can i fix it ?
I added it to build path
it did not help
Im using this now,
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("sun.jdbc.odbc.JdbcOdbcDriver found");
} catch (ClassNotFoundException cnfe) {
System.out.println("Error: sun.jdbc.odbc.JdbcOdbcDriver not found");
}
And it returns jdbcodbc not found, where can i get that ?
The issue with the Eclipse project was that it was actually running under Java 8, so the JDBC-ODBC Bridge was not available. Changing the run configuration to use a Java 7 JRE solved the problem.
If you want to do this correctly, add a folder called lib to your current project.
Download the jar for the driver and drag this jar from your file explorer in your lib folder in eclipse.
After this, right click your project folder -> java build path, look for the libraries tab and click add jars.
Browse to your jar in the lib folder and click OK. After this click ok again.
This should work :)
Try this:
Class.forName("com.mysql.jdbc.Driver");
If this doesn't work, you probably gave the wrong path.
Try searching in your referenced libraries in the package explorer view.
Just expand the jar and look for driver.class.
If this is to much work, your could try searching with shift + ctrl + r.
adjust your filter to your needs.
You need to search for the path of driver.class
I also suggest you not to use root and give it a strong password
You should open project property (alt+Enter), open menu "Deploy Assembly", and set libraries folder, where you have jdbc driver.
Something like this:

Classpath issue: Scala WAR webapp (jetty) fails to load on Windows but run flawlessly on Linux

On Windows 8.1 every time I start jetty (9.12) with
java -jar start.jar
It is able to find and deploy my WAR, but then shows an error message:
> 15:14:17.754 [main] ERROR n.liftweb.http.provider.HTTPProvider - Failed to Boot! Your application may not run properly
> java.lang.NoClassDefFoundError: scala/Seq
> at net.liftweb.json.DefaultFormats$.<init>(Formats.scala:175)
> ~[lift-json-2.0.jar:2.0]
> at net.liftweb.json.DefaultFormats$.<clinit>(Formats.scala)
> ~[lift-json-2.0.jar:2.0]
> at blah.rest.RestAPI$.<init>(RestAPI.scala:16)
> ~[classes/:na]
> at blah.rest.RestAPI$.<clinit>(RestAPI.scala)
> ~[classes/:na]
> at bootstrap.liftweb.Boot.boot(Boot.scala:28) ~[classes/:na]
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_03]
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_03]
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_03]
> at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_03]
>
> ....
And
Caused by: java.lang.ClassNotFoundException: scala.Seq
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.7.0_03]
at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.7.0_03]
at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_03]
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.7.0_03]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.7.0_03]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.7.0_03]
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:436) ~[na:na]
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:389) ~[na:na]
... 65 common frames omitted
On the other hand, when I deploy the same war in my Ubuntu 13.10 environment, it runs without complaining anything.
I have set my CLASSPATH variable to include scala (something like .;C:\Program Files\Java\jdk1.7.0_03\lib;C:\scala\lib;C:\scala\lib\scala-library.jar), and SCALA_HOME appropriately.
I also tried
java -jar start.jar -lib=blah....
Is there anything I haven't done right / anything extra I need to do?
This appears to be a classpath problem. Somehow it's not able to find Scala libraries.
I would suggest to run jconsole - it comes together with standard JDK package. Select the java process in it on Windows and Linux and compare classpaths. For example I get this on my machine in jconsole:
VM arguments: 
Class path: 
/somepath/myapp.jar
Library path: 
/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
Boot class path: 
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/netx.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/plugin.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rhino.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jfr.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/classes
Note that my app is packaged as a single jar and this jar itself is on the classpath. It contains scala-library-2.10.3.jar and scala-reflect-2.10.3.jar packaged within. Perhaps in your case the jar does not have Scala libraries and they are not on the classpath either.
The issue was resolved by changing dependency libraries compiled against a single corresponding Scala version.

ClassNotFoundException:scala.PreDef$ issue

I am trying to package a simple executable Jar written in Scala, through Eclipse's Export function.
When attempting to execute the Jar from cmd java -jar test2.jar
I get the following error. Any ideas? Thank you.
Caused by: java.lang.NoClassDefFoundError: scala/Predef$
at Parser.Test(Parser.scala:5)
at Main.main(Main.java:12)
... 5 more
Caused by: java.lang.ClassNotFoundException: scala.Predef$
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 java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
You just need to add the scala library jar to the classpath.
You can do it like this (assuming that the "scala-library.jar" jar is in the current directory) :
java -cp scala-library.jar -jar test2.jar
The documentation for tha java comamnd can be found here: http://docs.oracle.com/javase/6/docs/technotes/tools/windows/java.html
for me i was using jdk 11 and scala library container 2.12.3 and when i changed to jdk 8 it works fine
it is because of jdk11 scala version support
JDK Compatibility
right click on the project , Build path ,configure Build path , edit your jdk to less than 11
You can also package scala library together with your project. See this post
I did removed "Scala Library container" from project.
Next - add needed scala's library (scala-library.jar) to Java BuildPath (in Properties for ) as "Add External JARs..." in my library (not as reference to scala lib). And innclude them all to "Order and Export"
Finally - do Export for project with option "Package required libraries into generate JAR"
and this works fine :)

java.lang.NoClassDefFoundError while running JUnit

Hi i am getting this error please help me out, thanks
java.lang.NoClassDefFoundError: com/ge/energy/wp/core/exception/WPException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class`enter code here`.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at org.junit.internal.requests.ClassRequest.hasSuiteMethod(ClassRequest.java:62)
at org.junit.internal.requests.ClassRequest.getRunnerClass(ClassRequest.java:50)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:28)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:30)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.ClassNotFoundException: com.ge.energy.wp.core.exception.WPException
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 15 more
try adding source folder to your classpath. If you use eclipse, right click test file and select Run configuration under Junit test and select classpath and add your source folders to class path.
Check class WPException. Usually your IDE should show you if something is wrong with the java file but not with the class file - either it wasn't compiled or missing (the error is triggered when the JVM can't find the class) for some other reason, one of them could be, like bluelabel mentioned, a problem with the PATH.
I know this is old post...but may help someone else...
whenever I have faced this issue only problem have been the java version eclipse is defaulted to - which is the eclipse jre.
Fix - change to the proper jre installed on your machine !