java.lang.NoClassDefFoundError when running via Eclipse - java

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...

Related

Build Problem with AnysoftKeyboard (Android)

I am trying to build AnysoftKeyboard in Android studio.
I have java 9(jdk 9) and the appropriate ndk (android-ndk-r14b), as the creator in GitHub says.
I have also changed the local.properties file to shows to the correct paths.
Nevertheless I am still getting some errors.
You can find below those errors.
Run tasks error :
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':base:compileDebugJavaWithJavac
java compiler errors : Caused by: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: com/sun/tools/javac/util/JavacMessages$ResourceBundleHelper
Caused by: java.lang.NoClassDefFoundError: com/sun/tools/javac/util/JavacMessages$ResourceBundleHelper
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.util.JavacMessages$ResourceBundleHelper
Here is a screenshot of the error :
AnySoftKeyboard Compile Error , Run Tasks Error
The project uses gradle, in which I am not familiar with, so if I have missed any important step-point, please guide me to solve it.
Is there something that I am missing and getting these errors? What should I do? Thanks in advance.
After following just the official documentation I successfully built a project. I think you just forget with setting JAVA_OPTS with adding java.se.* source as mentioned below. And that is why you have it in stacktrace error above, with missing java.se. resources.
To develop this project, you'll need:
Java 10 - get OpenJDK or AdoptOpenJDK.
Make sure you have the environment variable JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'. This is required to ensure the JVM is merciful with libraries that were not designed for Java9+ JVMs.
git
Android Studio
Android SDK API Level 28 installed. Set up local.properties file to point to it (that is, ensure you have sdk.dir=/path/to/android/sdk in it).
Android NDK r14b installed. Set up local.properties file to point to it (that is, ensure you have ndk.dir=/path/to/android/ndk in it).
Caused by: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: com/sun/tools/javac/util/JavacMessages$ResourceBundleHelper
TO remove this error comment below line prone error.

Exception in thread "main" java.lang.NoClassDefFoundError: org/javatuples/Unit

I have imported the javatuples-1.2.jar in Eclipse project. I did this to run the Java Tuples Unit class program. The following is the code:
package mynewpackage;
import org.javatuples.Unit;
class Mynewclass2 {
public static void main(String[] args)
{
Unit<String> u
= new Unit<String>("This is demo text!");
System.out.println(u);
}
}
But, getting the following error on running:
Exception in thread "main" java.lang.NoClassDefFoundError: org/javatuples/Unit
at mynewpackage.Mynewclass2.main(Mynewclass2.java:9)
Caused by: java.lang.ClassNotFoundException: org.javatuples.Unit
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
Under the references, I can easily see that the tuples jar file is successfully added. However, the following is the project directory, jar in references, error, and the entire program in Eclipse.
How can I fix the issue and run Java Tuples programs correctly?
You have java 11 in place...
When I (try to) reproduce your setup:
My eclipse (Version: 2018-12 (4.10.0), Win_64_jdk_11.0.2) asks me for "module name" and adds src/module-info.java after creation of a "Java Project", ... then download and add lib/javatuples-1.2.jar to build path.
When I try to use/import it in my code (main class) - compilation error, and auto-correct proposes me to add "javatuples" module to module-info:
click-clack:
myproject/src/module-info.java
module myproject {
requires javatuples;
}
After that the program is already runnable, but Eclipse warns:
Name of automatic module 'javatuples' is unstable, it is derived from the module's file name.
To fix this, you can run (from command line):
myproject>jar --file=lib/javatuples-1.2.jar --describe-module
No module descriptor found. Derived automatic module.
javatuples#1.2 automatic
requires java.base mandated
contains org.javatuples
contains org.javatuples.valueintf
So, eclipse warning is already sort of nasty: javatuples is the "correct" module name.
Hope it helps.
Right Click on javatuples-1.2.jar > Build path > Add to Build Path .
NoClassDefFoundError is an error that is thrown when the Java Runtime System tries to load the definition of a class, and that class definition is no longer available.
Comments are Welcome.

Problems with MCP 9.03

I'm attempting to create a Minecraft mod using the 1.7.2 release of MCP, version 9.03. I may be doing the installation steps wrong, as when I complete the installation, open Eclipse and select the workspace, it gives me 7 errors that I have no idea how to solve. These are the errors:
Project 'Client' is missing required library: 'jars/libraries/org/lwjgl/lwjgl/lwjgl/2.9.0/lwjgl-2.9.0.jar'
Project 'Client' is missing required library: 'jars/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.0/lwjgl_util-2.9.0.jar'
Project 'Client' is missing required library: 'jars/libraries/org/lwjgl/lwjgl/lwjgl- platform/2.9.0/lwjgl-platform-2.9.0-natives-windows.jar'
Project 'Server' is missing required library: 'jars/minecraft_server.1.7.2.jar'
Project 'Client' is missing required library: 'jars/libraries/net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-windows.jar'
The project cannot be built until build path errors are resolved
The project cannot be built until build path errors are resolved
If I attempt to run without making any changes, this is the error that is displayed in the console:
Exception in thread "main" java.lang.NoClassDefFoundError: Start
Caused by: java.lang.ClassNotFoundException: Start
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Please help me out, I'm not using Forge as I plan to be making changes to base class files.
Open up eclipse and right click on the project "Client", go to build path, configure build path, click on all of the errored files and press remove. Then download the latest LWJGL (http://lwjgl.org/) and extract it to some folder, and import all of the jars. Next, get the natives for all platforms and put them in a new file called LWJGL-Natives.jar and import that as well.
Also, PLEASE do not do a base edit mod! It's bad practice, and will make your mod get little to no use. Try to use either the forge tweak utilities or the official one by mojang: https://github.com/Mojang/LegacyLauncher
Plus, you most likely can do whatever you want to do without ASM or base edits, so please try those before doing base edits.
For project "Server", remove the dependency for the broken resource. It will continue working fine.

Where do I get the missing resources?

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.

Class in buildpath-jar still not found

I'm developing a eclipse plugin rcp and I'm running into a NoClassDefFoundError
Exception in thread "Thread-7" java.lang.NoClassDefFoundError: org/jdom/input/SAXBuilder
at org.geonames.WebService.search(WebService.java:783)
at geo.GeocoderGeonames$SearchThread.run(GeocoderGeonames.java:119)
Caused by: java.lang.ClassNotFoundException: org.jdom.input.SAXBuilder
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:483)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 2 more
The class that supposedly cannot be found is in a jar that I have added to the buildpath. I don't get any compile error etc only this exception when the running application enters the code where this class is needed...
Is there some other place I need to add the jar
After reading this added the jar to the MANIFEST.MF, which solved the problem.
As I understand it, eclipse starts several classloaders which only sees what MANIFEST.MF tells them to see and ingnores the build path...
How are you running your plug-in? You may need to add the JAR to the class path in the VM arguments.
In our experience a NoClassDefFoundError can sometimes mean that more than one version of a Class are found, as there is also a ClassNotFoundException that's normally thrown if a class cannot be found.
Another reason in your case (XML parser) might be something with endorsed classes. Are you directly importing the jdom classes or something like org.w3c...? If so, have a look at the "endorsed classes" system of Java, something that I just recently came across.

Categories

Resources