Im trying to download a Spring/Java code from a book to run their code and test it but unfortunately I get errors,
I see this is a common error but don't see a fix for my pom file,
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.apress.springrecipes</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>springintro</artifactId>
<name>Introduction to Spring</name>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.javaee</groupId>
<artifactId>jboss-jca-api</artifactId>
</dependency>
</dependencies>
</project>
Error
Jul 17, 2013 3:51:20 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#be41ec: startup date [Wed Jul 17 15:51:20 EDT 2013]; root of context hierarchy
Jul 17, 2013 3:51:20 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:465)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:395)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.apress.springrecipes.hello.Main.main(Main.java:10)
Caused by: java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:141)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 13 more
Pom file error:
maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e.
maven-resources-plugin prior to 2.4 is not supported by m2e. Use maven-resources-plugin version 2.4 or later.
What #Pace said is totally valid, and I believe OP should try to understand what m2e is doing. Personally I hate the behavior of m2e after 0.10, for which they introduced the connector concept. The concept is good but the way to tell Eclipse how to react to unsupported plugins is by seriously polluting the POM which looks awful to me. Switching back to older M2E version may make your life easier though you lose some feature.
Going back to your question, from the error message you quoted:
maven-resources-plugin prior to 2.4 is not supported by m2e. Use maven-resources-plugin version 2.4 or later.
it seems suggest to me that m2e did support maven-resources-plugin >= 2.4 (I am not sure, I haven't encountered similar issue as you before). Try to make use of newer version (2.4 or after, latest is 2.6) of maven-resources-plugin in your POM, M2E may be able to pick up the settings for you.
i.e.
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
....
</pluginManagement>
....
</build>
</project>
it is always a good practice to stamp the version of plugins you used. This lead to a more "reproducible" build.
m2e is not Maven. The POM file error is saying that Eclipse's Maven plugin (m2e) does not know what to do with the "copy-dependencies":"unpack" goal. The way m2e works it has to understand what a goal does in a pom file so that it can duplicate that behavior in the Eclipse build.
There are a two main things you can do:
Tell Eclipse to ignore the goal - This will allow you to not get the error. That unpack step will never occur during Eclipse incremental builds, it will still happen when you do full Maven builds.
Install a "connector" which tells Eclipse what to do when it encounters that goal. The connector for this goal can be found here.
As for the maven-resources-plugin I don't see any other option than upgrading the plugin version specified in the POM. The error there is saying that Eclipse's Maven plugin can't work with Maven plugins that old.
I have no idea what is causing the file not found error but suspect it is because that file is contained in whatever it is that Eclipse is not unpacking.
Related
I want to include XStream in my RCP project and used a Maven Dependency to add it to my target definition.
<location includeDependencyDepth="infinite" includeDependencyScopes="compile,provided,runtime,test,system,import" includeSource="true" missingManifest="generate" type="Maven">
<dependencies>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.20</version>
<type>jar</type>
</dependency>
</dependencies>
</location>
From this diagram, it seems like xmlpull is present but XStream throws ClassNotFoundException in the constructor.
java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserException cannot be found by xstream_1.4.20
Looking more closely, I see that there are a number of new plugins named wrapped.bundlename. I then reconfigured the Maven Dependency to produce a feature and added the feature to my core feature.
The run configuration picked up the new feature but xmlpull was still not found at runtime. In desperation, I added all plugins (xmlpull included) to the run configuration but there was no improvement.
Is this the right approach for creating plugins from maven dependencies?
I'm writing Selenium Junit tests with IntelliJ. The tests run ok if I trigger from test directly. However, if I trigger tests from TestRunnerSuite with JunitCore, I encountered following weird error that I did not find a solution after researching on google. Similar questions on DriverService$builder, but not my error type.
[main] ERROR sire.responseOrg.TestIncidents - java.lang.AbstractMethodError: org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList;
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:332)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at sire.responseOrg.WebDrivers.getInstance(WebDrivers.java:15)
at sire.responseOrg.util.util1.setupChromeDriver(util1.java:51)
at sire.responseOrg.Test1.setUp(Test1.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at ......Omitted
at org.junit.runner.JUnitCore.run(JUnitCore.java:127)
at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:76)
at sire.responseOrg.TestSuiteRunner.main(TestSuiteRunner.java:24)
I'm using Selenium 3.5.3 and chrome 76.---> Updated to Selenium 3.141.59,and with main scope.
Now getting error
java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:93)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:72)
at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:63)
at org.openqa.selenium.chrome.ChromeDriverCommandExecutor.<init>(ChromeDriverCommandExecutor.java:36)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at sire.responseOrg.WebDrivers.getInstance(WebDrivers.java:15)
at sire.responseOrg.util.SeleniumUtil.setupChromeDriver(SeleniumUtil.java:62)
at sire.responseOrg.TestIncidents.setUp(TestIncidents.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
at org.junit.runner.JUnitCore.run(JUnitCore.java:127)
at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:76)
at sire.responseOrg.TestSuiteRunner.main(TestSuiteRunner.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.http.auth.Credentials
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 33 more
Full pom.xml dependencies
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myGroupId</groupId>
<artifactId>myArtifactId</artifactId>
<version>1.0-SNAPSHOT</version>
<description>My description</description>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>main</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
<scope>main</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
<scope>main</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.6</version>
<scope>main</scope>
</dependency>
<dependency>
<groupId>com.salesforce.seti</groupId>
<artifactId>selenium-dependencies</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<packaging>pom</packaging>
</project>
My project folder structure is
.src
...main
.....java
.......projectname
.........constantsFolder
.........utilFolder
...........util1.java
...........util2.java
.........Test1.java
.........TestRunnerSuite.java
.........WebDrivers.java
If I start test from Test1.java, the test runs regularly though with warnings
[main] INFO projectname.util.util1 - Set up chrome driver.
Starting ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770#{#1003}) on port 28755
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1566609934.853][WARNING]: This version of ChromeDriver has not been tested with Chrome version 76.
Aug 23, 2019 6:25:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[main] INFO projectname.util.util1 - Navigating to https://mytest.com/
However, after adding a testSuiteRunner as below.
#RunWith(Suite.class)
#Suite.SuiteClasses({ Test1.class })
public class TestSuiteRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(Test1.class);
// print erros, exit etc omitted
}
}
Now I get the weird error and cannot fire the chromedriver.
The webdriver I have is singleton
public class WebDrivers {
private static WebDriver driver = null;
public static WebDriver getInstance(){
if (driver == null) {
driver = new ChromeDriver();
}
return driver;
}
}
It's my first time to work on setting everything up from grounds. I'm not sure if it's pom dependency issue, singleton webdriver issue, or something else. Could anyone share an eyesight on this and give some clues? Much appreciated.
This error message...
java.lang.AbstractMethodError: org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList;
...implies that there is some incompatibility between the version of the binaries you are using specifically with the guava dependency.
You are using chrome= 76.0
You are using the following:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.5.3</version>
<scope>test</scope>
</dependency>
Your Selenium Client version is 3.5.3 which is more then 2 years older.
Your JDK version is unknown to us.
So there is a clear mismatch between the Selenium Client v3.5.3 and Chrome Browser v76.0
However as per the discussions in:
java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.builderWithExpectedSize
NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector; after upgrade to 2.0.16
These issues crop up due to incompatibile Guava dependency.
The current guava version used within selenium-java-3.141.59 is guava-25.0-jre
Solution
Ensure that:
JDK is upgraded to current levels JDK 8u222.
Selenium is upgraded to current levels Version 3.141.59.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Update
So presumably your main question with respect to the error:
java.lang.AbstractMethodError: org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList;
is solved. Congratulations.
Now, as per your question update as you are seeing the error:
java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials
There are two aspects.
NoClassDefFoundError: NoClassDefFoundError in Java occurs when Java Virtual Machine is not able to find a particular class at runtime which was available at compile time. You can find a detailed discussion in Exception in thread “main” java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
http/auth: Traces of http/auth implies http client is still in use where as the CHANGELOG reflects:
The HttpClient implementation details were out of HttpCommandExecutor right from Selenium v2.45.0.
With the availability of Selenium v3.11, Selenium Grid was switched to use OkHttp rather than the Apache HttpClient.
Further with the release of Selenium v3.141.0, Apache HttpClient was removed from selenium-server-standalone which drastically
reduced the size of selenium server distribution package.
Even the apache-backed httpclient was also removed.
You can find a detailed discussion in org.openqa.selenium.remote.internal.ApacheHttpClient is deprecated in selenium 3.14.0 - What should be used instead?
Remove scope from your POM.
test
or main
Isn't needed for your tests to run
used this gauva jar with latest testng 7.3. Resolved this error also dont configure any testNG seperately. Please remove configuration if we add it in pom.xml
I was facing the same issue. The following steps helped resolve it:
Go to your POM file and comment out/ remove the following dependency:
--> org.seleniumhq.selenium
--> selenium-java
--> 2.48.2
Check what version you have.
Then copy the latest mvn dependency which is 4.1.1 as of now
Perform mvn clean install (till this point it will be sufficient)
Perform reload all maven projects
Perform download sources
Build your project again
Play/ perform mvn clean install again
FYI: as per my knowledge, this issue occurs at compile time when you execute the code. Or the time when you execute a code in a new project which was compiled with different dependencies and versions earlier.
I'm trying to use checkstyle and findbugs by doing mvn checkstyle:checkstyle but I have this error
This error
[ERROR] Failed to execute goal on project my-project: Could not resolve dependencies for project default:my-project:jar:1.1: Could not find artifact com.sun:tools:jar:0 at specified path C:\Program Files\Java\jdk-11.0.2/../lib/tools.jar -> [Help 1]
I do not have a tools.jar into my JDK (i have jdk-11.0.2).
I'm on it since 2H, please help :/
tools.jar removed from Java 9+
You're on JDK 11. No tools.jar found there.
JEP 220: Modular Run-Time Images removed both tools.jar and rt.jar from the lib folder, as of Java 9.
Removed: rt.jar and tools.jar
The class and resource files previously stored in lib/rt.jar,
lib/tools.jar, lib/dt.jar, and various other internal JAR files are
now stored in a more efficient format in implementation-specific files
in the lib directory. The format of these files is not specified and
is subject to change without notice.
This change is part of adding the Java Platform Module System, a.k.a. Project Jigsaw.
To upgrade Checkstyle, use later versions, such as:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.18</version>
</dependency>
</dependencies>
</plugin>
Notice the inner dependency block.
Consult a Maven repo for versions of Apache Maven Checkstyle Plugin and of Checkstyle.
new user here!
I know there's similar questions with answers to this, but I don't know how to apply them to my case, so sorry if it's repetitive!
So... I'm trying to make my first bot for Telegram and I've decided to use Java. I'm following this tutorial and copypasted the code from the two example classes (EchoBot and Main). The only thing I changed is the token with the token I got from the BotGodfather on Telegram.
I'm using Eclipse on Ubuntu 18.04.1 as IDE so I started by making a Java project and then configured it as a Maven project. This is the code of my pom.xml:
`
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>EchoBot</groupId>
<artifactId>EchoBot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>EchoBot</name>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
`
When I run the program I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Module
at org.telegram.telegrambots.ApiContext.getInjector(ApiContext.java:46)
at org.telegram.telegrambots.ApiContext.getInstance(ApiContext.java:25)
at org.telegram.telegrambots.bots.TelegramLongPollingBot.(TelegramLongPollingBot.java:17)
at pearlbot.EchoBot.(EchoBot.java:8)
at pearlbot.Main.main(Main.java:17)
Caused by: java.lang.ClassNotFoundException: com.google.inject.Module
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 5 more
What could the problem be?
Keep in mind that I don't even know what Maven is, so if it's something related to it, you'll need to explain what's wrong as if you were talking to a child! ^^''
I got this error when i try to install testng for eclipse Version: 2019-12 (4.14.0) and run the program then i got this error. Finally i got fixed -
Eclipse IDE for Java Developers, Version: 2019-12 (4.14.0), Build id: 20191212-1212.
TestNG 7.1.0.r202001120626
Removing the TestNG library from the build path of the project containing the test and installing TestNG from menu Help / Install New Software did not work for me, I kept getting this error.
What worked for me was downloading guice-4.2.2.jar (from https://github.com/google/guice/wiki/Guice422), copying it into any folder, and adding it to the build path of the project as external JAR.
From Eclipse, Go to Help > Install software or You can install from market place as well (Help > Market Place). After installing TestNG from market place, it dint work, but installing the GUICE422.jar to the build path worked for me
So make sure after installing TestNG from market place, install the Guice422 Jar file as well link to install testng from eclipse market place
This worked for me --- Hope it helps
I have added the most updated Selenium dependency in my pom.xml
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.7.1</version>
</dependency>
I ran
mvn clean install
inside the directory with my pom.xml and I have also imported the correct classes in my app class as per the Selenium documentation
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
However when i try and run my main method, I get the following error
Exception in thread "main" java.lang.NoClassDefFoundError:
org/openqa/selenium/WebDriver
I look in my ~/.m2/repository folder and I don't see an openqa folder but instead I see a seleniumhq folder.
Why didn't maven install the openqa folder, and why does the documentation say to import from org.openqa... when that never exist in my jar repository. I'm very confused, I just want to be able to import selenium Webdriver successfully while having it in my local repository.
Firstly, check properly if you have all important dependencies for your program.
Secondly, I had similar error while running maven project:
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/JavascriptExecutor
And this problem was because of inappropriate plugin, because I tested different versions of Selenium and it didn't help me.
So when I changed maven-jar-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>your_main_class</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
to maven-shade-plugin plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>your_main_class</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
The issue was gone.
The difference between plugins you can find here.
In addition, sometimes we upgrade our libraries even with same method name. Due this different in version, we get NoClassDefFoundError or NoSuchMethodError at runtime when one library was not compatible with such an upgrade.
Java build tools and IDEs can also produce dependency reports that tell you which libraries depend on that JAR. Mostly, identifying and upgrading the library that depends on the older JAR resolve the issue.
To summarize:
try to change versions of Selenium, if it contains all dependencies;
try to add necessary dependencies if you don't have it;
try to check folder of maven if it has or not what says specific error;
try to play with plugins if nothing helps above.
NoClassDefFoundError
NoClassDefFoundError in Java occurs when Java Virtual Machine is not able to find a particular class at runtime which was available at compile time. For example, if we have resolved a method call from a class or accessing any static member of a Class and that Class is not available during run-time then JVM will throw NoClassDefFoundError.
The error you are seeing is :
Exception in thread "main" java.lang.NoClassDefFoundError:
org/openqa/selenium/WebDriver
This clearly indicates that Selenium is trying to resolve the particular class at runtime from org/openqa/selenium/WebDriver which is no more available.
As you mentioned of looking into ~/.m2/repository folder, the maven folder structure for Selenium v3.7.1 (on Windows) is as follows :
C:\Users\<user_name>\.m2\repository\org\seleniumhq\selenium\selenium-java\3.7.1
So when you see a seleniumhq folder, it is pretty much expected.
What went wrong :
From all the above mentioned points it's clear that the related Class or Methods were resolved from one source Compile Time which was not available during Run Time.
This situation occurs if there are presence of multiple sources to resolve the Classes and Methods through JDK / Maven / Gradle.
Solution :
Here are a few steps to solve NoClassDefFoundError :
While using a Build Tool e.g. Maven or Gradle, remove all the External JARs from the Java Build Path. Maven or Gradle will download and resolve all the required dependencies.
If using Selenium JARs within a Java Project add only required External JARs within the Java Build Path and remove the unused one.
While using Maven, either use <artifactId>selenium-java</artifactId> or <artifactId>selenium-server</artifactId>. Avoid using both at the same time.
Remove the unwanted other <dependency> from pom.xml
Clean you Project Workspac within your IDE periodically only to build your project with required dependencies.
Use CCleane tool to wipe away the OS chores periodically.
While you execute a Maven Project always do maven clean, maven install and then maven test.
Encountered this error in Eclipse IDE. In Eclipse go to Project properties and in Java Build Path just add selenium jars in Classpath instead of Modulepath. Then under the Project tab on the top do a Clean to remove earlier buiid and then do a Run.
Are you using an IDE or working from command line? In Eclipse for example you can force downloading all dependencies by right clicking on your project, going to Maven menu item and then selecting Update Project. Then check the "Force Update of Snapshots/Releases" checkbox.
If you are opening from command line do:
mvn clean install -U
from your project path.
This is happening because you are selecting jar files under modulepath, you should add them under class path.
org.openqa.selenium is the package in the selenium-api-{version}.jar under the seleniumhq\selenium\selenium-api folder.
org.openqa.selenium.firefox is the package in the selenium-firefox-driver-{version}.jar under the seleniumhq\selenium\selenium-firefox-driver folder.
So there is no openqa folder, it's just the package name under the seleniumhq folder, you should have a check into these jar.
It's hard to say what caused NoClassDefFoundError exception without project structure and code detail. The exception is not the same as ClassNotFoundException. Maybe this answer https://stackoverflow.com/a/5756989/5374508 would be helpful.
What worked for me was to add this dependency to pom.xml:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.0-jre</version>
</dependency>
I was getting below error from past 2 days and what helped me was to remove all the selenium extra dependencies like selenium-support, selenium-chrome-driver etc and only keeping the below dependencies in POM file.
Error:-
java.lang.NoClassDefFoundError: org/openqa/selenium/HasAuthentication
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
Dependencies in the pom file after removing all other:-
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Have encountered this issue while running selenium test in eclipse IDE.
Navigate to following path:
1.Properties >> Java build path >> Libraries.
2.Add all selenium jars in Classpath instead of Modulepath.
3.Apply and close modal.
4.Now go to build path and click on "Configure Build Path".
5.Now run the selenium test.