I have this Problem. When i run my code in Intellij it works fine, but if i do an artifact and build the jar, it doesnt work. I think its caused by an extern library. Heres my output:
Exception in thread "main" java.lang.NoClassDefFoundError: com/mindfusion/scheduling/Calendar
at GUI.<init>(GUI.java:75)
at Logfiles.main(Logfiles.java:13)
Caused by: java.lang.ClassNotFoundException: com.mindfusion.scheduling.Calendar
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)
... 2 more
I know which Class it is but i dont know how to solve the Problem. Im really just a beginner. Could you please help me and explain it simple. Thank you
Edit:
After i build the artifact with extracted Libraries this Error comes : Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
This error simply means the class file is not present in the jar.
One possible solution is you can download jd-gui which is used to look at jars. You can use this to check if the class is present.
Another solution is you can grep search the class in the jar with this simple command.
grep -l "<class-name>" <jar-name>.jar
if the class is not present in the jar file. you can add the class using jar command.
jar -cvf <jar-absolute-location> <class-path>
eg : jar -cvf GUI.jar com.mindfusion.scheduling.Calendar
The easiest way to understand this issue, it to read the Javadoc for that class. From the Javadoc:
Thrown if the Java Virtual Machine or a ClassLoader instance tries to
load in the definition of a class (as part of a normal method call or
as part of creating a new instance using the new expression) and no
definition of the class could be found.
The searched-for class definition existed when the currently executing class was compiled,
but the definition can no longer be found.
That means that NoClassDefFoundError can be thrown when that particular class is present during compile time but somehow not available during runtime. This could be due to missing JAR file, permission issues, or incorrect classpath on runtime.
Normally I see these issues when developers neglect to define the classpath for used libraries. They forget that your IDE has its own file defining the classpath (i.e. Eclipse has the .classpath file) so running the application from the IDE works fine (class is present during compile time), but after the application is compiled and the classpath is not defined in the machine hosting the application, NoClassDefFoundError is thrown (class "missing" at runtime).
My suggestion is figured out first if the classpath is correct. More times than none, this is the issue. If the classpath is correct, make sure all permissions are set correctly.
Related
I'm following this sample to test purview SDK for java, it could be built successful, but when I run this java file ,it shows "Exception in thread "main" java.lang.NoClassDefFoundError: org/reactivestreams/Publisher". the class "DefaultAzureCredentialBuilder" was defined in core-identity jar and I already imported it ,not clear why it still failed and what class it required?
here is my code content
We get this error when the class is not available in the program at runtime but class was successfully compiled by the java compiler.
The reason why you are getting this error is because of jre unable to find DefaultAzureCredentialBuilder class.
As you mentioned in the post that this class is defined inside core-identity jar. whether the jar file may be missing. So, try to import it again and check.
I'm trying to import a jar that I created to my project in Eclipse. When trying any calls from the so-called jar, I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError
Caused by: java.lang.ClassNotFoundException
I believe this is caused due to the class being present on compile, but not being executed in runtime.
The problem is: When I run the jar on its own (without being imported), it works as intended, with all the functionalities. But I now need it to function as being part of a bigger jar, without changing the runtime classpath (didn't do that to the original project).
How can that be achieved?
#Edit
The class not being found or def not being found is ByteList, from the FastUtil library.
Exception in thread "main" java.lang.NoClassDefFoundError: it/unimi/dsi/fastutil/bytes/ByteList
It's imported TO another Jar, let's call it MyJar.jar; MyJar.jar functions perfectly as a standalone jar, as the intention for it is to be a library, and it functions by itself.
The situation is: When I import MyJar.jar to another project, it won't work anymore, I can't use it's methods and classes inside the new project.
MyJar.jar can be run from the command prompt, with java -jar MyJar.jar, and it will print it's test-page to show that it's working.
The new project compiles, but when it's ran, I get the class not found exceptions regarding MyJar project.
You can use Maven Assembly Plugin to add all classes from related JARs, otherwise you cannot load classes without adding them to classpath.
If you don't want to use Maven then add all needed classes manually to your JAR.
If an exception occurs due to a missing jar file, then is there any way to back track and find out the missing jar file?
Suppose the following exception:
java.lang.NoClassDefFoundError:
org/apache/commons/httpclient/HttpMethod
which is caused by missing commons-httpclient-3.0.1.jar file.
There is no way you can find which jar have which class file. You can only find out package structure of missing class like org/apache/commons/httpclient based on that if you can guess which jar is missing.
And its hard because any jar can have classes in any package structure.
I use findjar (http://findjar.com/index.x) to know which jar will contain a specific class based on which i will investigate whether jar is in classpath or not
As was meant above, java compiler gives us info about missing classes, not jars.
You can try find jar, containing particular class by its short or fully specified name, for example org/apache/commons/httpclient/HttpMethod,
using web resources, as jar-download.com, findjar.com or search.maven.org
java.lang.NoClassDefFoundError: Could not initialize class org.apache.axis.utils.XMLUtils
I am getting this error. How to avoid this exception. Please suggest me a solution.
According to Oracle:
NoClassDefFoundError is thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
In simple language, it means "At compile-time class was there but at run-time, it failed to find/load the class
Question comes : How come my code compile?
Answer maybe because you added jars using Eclipse. But Eclipse does not actually move those jars into you classpath.It just uses those referenced jars while compilation. So your code compiles fine.
After, you move your project to tomcat, when it tries to load some class inside those 'jars', it fails to find the class,because you never moved those jars to the classpath.
Solution:
Move all the libraries(jars) into your project's /WEB-INF/lib. Now all the libraries/jars under /WEB-INF/lib will come under classpath.
You can read more on Oracle's Docs & this article
NoClassDefFoundError means, a library that was available at the compile time, is not available at the runtime.
In this case it's the jar file containing the class org.apache.axis.utils.XMLUtils. Make sure it is available in your classpath.
This exception probably means that an instance has to be created by reflection, but the corresponding class is not in the execution classpath. Check your execution classpath.
It is also possible that the creation of the new instance depends on some configuration that is wrong or absent. Check your execution configuration files.
NoClassDefFoundError means the compiler trys to load the class at compile time but the required class is not available at compile time.
So add the required jar file to your program. Can you add this jar file: axis-1.2.jar
I am trying to run a java program on my AIX server. I wrote the classpath
/usr/java6/bin/javac -classpath :.:/usr/jdk/commons-net-3.0.1.jar:/usr/jdk/classes12.jar:/usr/jdk/mysql-connector-java-5.1.17-bin.jar:/usr/jdk/jtds-1.2.5.jar:/urs/jdk/mail.jar:/usr/jdk/joda-time-1.6.2.jar:/usr/jdk/commons-codec-1.4.jar:/usr/jdk/commons-logging-1.1.1.jar:/usr/jdk/httpclient-4.1.1.jar:/usr/jdk/httpclient-cache-4.1.1.jar:/usr/jdk/httpcore-4.1.jar:/usr/jdk/httpmime-4.1.1.jar:/usr/jdk/mailapi.jar:/usr/jdk/pop3.jar:/usr/jdk/smtp.jar:/usr/jdk/dsn.jar:/usr/jdk/imap.jar -d . *.java
which seems to compile correctly. Then when I run the program
java daily_transmission
i get the error java.lang.NoClassDefFoundError: javax.mail.Address. All the .jar files that were in Eclipse when it worked before are in the /usr/jdk file.
A NoClassDefFoundError means that (quoting the relevant JavaDoc):
Thrown if the Java Virtual Machine or a ClassLoader instance tries to
load in the definition of a class (as part of a normal method call or
as part of creating a new instance using the new expression) and no
definition of the class could be found.
The searched-for class definition existed when the currently executing
class was compiled, but the definition can no longer be found.
Two things to check:
Firstly, you appear to have have a typo in your classpath (though it can't have been there when you compiled the code, or it wouldn't have compiled successfully, so that's clearly not the root cause of the exception you're seeing.):
/urs/jdk/mail.jar
should be
/usr/jdk/mail.jar
Make sure that you are also using the -classpath option to pass the classpath to java as well as to javac to pick up those .jar files at runtime:
java -classpath :.:/usr/jdk/commons-net-3.0.1.jar:/usr/jdk/classes12.jar:/usr/jdk/mysql-connector-java-5.1.17-bin.jar:/usr/jdk/jtds-1.2.5.jar:/urs/jdk/mail.jar:/usr/jdk/joda-time-1.6.2.jar:/usr/jdk/commons-codec-1.4.jar:/usr/jdk/commons-logging-1.1.1.jar:/usr/jdk/httpclient-4.1.1.jar:/usr/jdk/httpclient-cache-4.1.1.jar:/usr/jdk/httpcore-4.1.jar:/usr/jdk/httpmime-4.1.1.jar:/usr/jdk/mailapi.jar:/usr/jdk/pop3.jar:/usr/jdk/smtp.jar:/usr/jdk/dsn.jar:/usr/jdk/imap.jar daily_transmission
NoClassDefFoundError means that the ClassLoader was able to find the class, but it was not able to be loaded. This usually happens when some static field in the offending class could not be initialized. So I am sure that your classpath might be correct; but some static field in that class could not be set correctly.