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?
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.
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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.