I am working on a vanilla Eclipse project and trying to avoid using Maven.
I have added Jackson modules to the module path as an external jar. When I do so, the import statement no longer shows an error but when I run my program I get the following error
Exception in thread "main" java.lang.NoClassDefFoundError:
com/fasterxml/jackson/databind/ObjectMapper at
bitcoin.PriceConverter.getJsonFromUrl(PriceConverter.java:48) at
bitcoin.PriceConverter.main(PriceConverter.java:26) Caused by:
java.lang.ClassNotFoundException:
com.fasterxml.jackson.databind.ObjectMapper at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 2 more
Line 48 in PriceConverter is ObjectMapper objMapper = new ObjectMapper();
I have googled extensively and found that my classpath is potentially broken however, all of the answers are from outdated versions of Eclipse and I cannot work out how to fix this problem.
I tried the same thing with Gson and had the same problem however, yesterday I added the json-20210307.jar and it worked fine.
Can anyone explain what is happening here and guide me on how to fix it?
I get the following error messages when attempting to run my program via Eclipse:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/JavaVersion
at lemmini.LemminiFrame.main(LemminiFrame.java:762)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.JavaVersion
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
The project has all necessary dependencies loaded and there are now 0 errors in the code (there are some warnings though).
Ideas welcome. Thank you!
OK, it turns out that the issues I've been experiencing are all to do with the dependencies. I loaded them into a folder called 'dependencies' within the project folders (alongside 'src') and then imported them from there via Project>Properties>Java Build Path>Libraries (then choose Classpath>Add JARs)
I can now run the program within Eclipse, but can't run it as an executable .jar
The journey continues...
Ive been playing with junit over the past few weeks and Ive switched to a diffrent machine and for the life of me I cannot get JUnit to run successfully. This is the error that eclipse is giving me:
java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:333)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadTestLoaderClass(RemoteTestRunner.java:380)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:370)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:365)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:309)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:224)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:208)
Caused by: java.lang.ClassNotFoundException: org.junit.runner.manipulation.Filter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:604)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 8 more
I have my environment variables set correctly; JUNIT_HOME [points to c:/junit-4.10.jar] and CLASSPATH [points to %CLASSPATH%;%JUNIT_HOME%\JUnit4.10.jar;.;]
I hope someone can help me out with this, thanks!!
I managed to fix the issue, I had to go to java-->build path and I removed the .jar and the junit library from modulepath, I then added only the junit library under classpath and it works fine now; I am still confused, when I add the junit library it says source not found.
It looks like you are using the wrong version of JUnit and it doesn't have the classes or methods you are expecting.
This error
NoClassDefFoundError: org/testng/TestNG
appears when I'm trying to run my test from Testng.xml file using IntelliJ IDEA.
Running my test one by one works perfectly as well as running whole gradle project which points to testng.xml, like grade core-test:test
( On my project I'm using Appium + IntelliJ + TestNG )
But when I'm running testng.xml using IntelliJ I'm immediately getting this message after pressing Run:
Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/TestNG
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:120)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 18 more
I found a solution posted here: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206597869-Cannot-launch-NGTest-runner-in-IntelliJ-IDEA-2016-1
I got it to work by selecting "In whole project" (I had "In single
module" selected) under the Configuration tab in the TestNG "Run/Debug
Configurations."
However, the prior configuration worked in IntelliJ IDEA 15, so to me,
it seems that it may have come from a breaking change with newer IDE.
It worked for me.
adding a screenshot to aid Justin's answer above. The default is In single module which needs to be changed to In whole project.
For me it is a little different, i was using testng configuration file to run a testng suite. I was running it from the parent module instead of the child module. The following is what I did to overcome the error
Follow the steps -
1. Add the TestNG library from java build path - go to project --> right-click--> properties--> java build path --> third option libraries.
TestNG - sELECT and then apply and close
PLease follow following steps:
Add the TestNG library from in java build path for the project.
Right click on the project then -> Build path -> Configure build path -> Libraries tab -> Add library -> Choose TestNG and apply.
Create a testNG class and run the testng.xml file, it will work.
Right click on project -> testNG-> create testNG class -> give the details and create one method in that class then run the file.
for me, this was a little different still. I just started using IntelliJ in 2019, and it worked fine until around Christmas. Here is what finally fixed my misbehaving system that couldn't run IntelliJ (because i could run the same files from the same repository on another system running the same IntelliJ version)
Had to change the template TestNG to use a Test Kind of Suite instead of Class, then set this to whole project.
showing where i changed the project to Whole Project
Tried all the answers mentioned in this post, in addition to all this I had to remove Build from the section Before launch: Activate tool window to make it work:
Screen Shot
Mine was a little different, using Allure to generate reports with TestNG. In the Allure section of the gradle.build file, I needed to upgrade from 2.8.1 -> 2.13.8. For some reason 2.8.1 was causing the class not found exception for TestNG, some logging improvement needs to be made on their part.
def allureVersion = "2.13.8"
allure {
autoconfigure = true
aspectjweaver = true
version = allureVersion
clean = true
useTestNG {
version = allureVersion
}
}
I am still unable to get the box-api hello world program to work. I was getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/NotImplementedException
at TestProgram.getAuthenticatedClient(TestProgram.java:47)
at TestProgram.main(TestProgram.java:35)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.NotImplementedException
...
I then went to the Apache Commons Lang Home and downloaded and set up their thing.
Now I get
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at com.box.boxjavalibv2.jacksonparser.BoxResourceHub.<init>(BoxResourceHub.java:28)
at com.box.boxjavalibv2.BoxClient.createResourceHub(BoxClient.java:345)
at com.box.boxjavalibv2.BoxClient.<init>(BoxClient.java:65)
...
and I have no idea how to fulfill that dependency. I also suspect that even if I could find this one, there'd just be another one, and another one, and another one. Manually importing them all does not seem to be very realistic.
How am I intended to get the missing dependencies for the box API?
The SDK comes included with all of the dependencies you should need. You can find them all in the libs directory of the SDK..
Add all of those jars to your Eclipse build path and it should work.