Intellij Java: Jni error has occured - java

I've looked at many of the other similar questions posted but it seems that a lot of it is about exporting and using a .Jar file.
I'm trying to only compile my code. I had it on github but when I cloned and tried to compile the same program on a new computer, I get the following error:
java.lang.NoClassDefFoundError: com/intellij/uiDesigner/core/Spacer
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.intellij.uiDesigner.core.Spacer
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"
Process finished with exit code 1
I am currently using jdk 1.8, if anyone can help me compile my program it'll be great, here's a snippet of the main class
public static void main(String[] args) throws IOException {
JFrame frame = new JFrame("CertifyGUI");
frame.setContentPane(new CertifyGUI().panelMain);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}

This code uses classes from IntelliJ IDEA GUI Designer, for this code to compile and run you need to include these classes in the classpath and build the code from IntelliJ IDEA or using javac2 Ant task.
The missing classes are available in IDEA_HOME\redist\forms_rt.jar.
When building from IntelliJ IDEA, the required classes are copied to the output directory (classpath) automatically and the .class files are instrumented with the GUI initialization code based on the .form files.
There are ways to build it with Maven/Gradle/Ant in the command line, you can Google the relevant answers if that is what you need (javac2 maven, javac2 gradle, etc).

Related

NoClassDefFoundError even though jar is in the module path Eclipse

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?

java.lang.NoClassDefFoundError when running via Eclipse

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

IntelliJ Jar Error : Invalid signature file digest for Manifest main attributes

I'm using IntelliJ IDE on an armx64 linux-based system, where i'm working on a non-maven java project that have a lot of modules (dependencies) linked to it. When running my project from the IDE everything works fine, however when building it into a runnable jar file and trying to run the jar from the terminal, using java -jar myjar.jar, i got the following error:
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
at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:330)
at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:263)
at java.util.jar.JarVerifier.processEntry(JarVerifier.java:318)
at java.util.jar.JarVerifier.update(JarVerifier.java:230)
at java.util.jar.JarFile.initializeVerifier(JarFile.java:383)
at java.util.jar.JarFile.getInputStream(JarFile.java:450)
at sun.misc.URLClassPath$JarLoader$2.getInputStream(URLClassPath.java:977)
at sun.misc.Resource.cachedInputStream(Resource.java:77)
at sun.misc.Resource.getByteBuffer(Resource.java:160)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:454)
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:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
I'm currently using OpenJdk-1.8, i tried to use Oracle JDK v1.8 instead to build and then rerun the jar file, but still facing the same error. I'd also tried to create a new simple "Hello world" application and export a corresponding jar for it where it runs successfully without errors.
Here is my jar internal structure and the corresponding manifist file:
jar structure screenshot
Thanks for #y.bedrov who linked to this issue that helped my solving the error, where it includes the following:
"sqljdbc4.jar" was the signed JAR in OP's external libraries. So,
following above approach to systematically exclude the signature
related files like .SF, .RSA or .DES or other algorithms files is the
right way to move forward.
And yes I'm also using "sqljdbc4.jar", so after reading the answer i decided to solve the problem by deleting the signature files from my Meta-inf folder inside my jar file.

Program doing fine in eclipse and netbeans, but getting errors after building the .jar file

My program works fine in both eclipse and netbeans.
But after I clean and build in netbeans, or export as jar file in eclipse, the .jar file got an error.
Here is the code:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/xy/XYDataset
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.jfree.data.xy.XYDataset
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)
... 7 more
I have added all the paths of the library to manifest, still error.
The only way it works is to use eclipse and export it to runnable jar file.
My program will take an int or string (stock code) that users input in the textfeild then it will generate an url to download a csv file to get data and graph. The runnable jar file can works well and generate graph when the stock code that is inputted by the user is a string, but when the user input an int, it can't plot the graph. Why is it having problems with the ints, it works well in eclipse and netbeans and I don't have console to see if there is a error code of the jar file.
thanks for advice!
It would be usefull if you can explain how you are compiling the jar.. the problem is because you are not including the external libraries inside your jar. You could try one of the following ways if you have the external library
http://javarevisited.blogspot.com/2012/10/5-ways-to-add-multiple-jar-to-classpath-java.html

ClassNotFoundException in IntelliJ IDEA

I have received an IntelliJ project from someone else, but it won't run even the simplest classes for me.
As a quick example, the following class will throw a ClassNotFoundException without compiler errors:
package myPackage;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println("Soon our GUI will start from here!");
System.exit(0);
}
}
This will throw the following error:
Exception in thread "main" java.lang.ClassNotFoundException: myPackage.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Process finished with exit code 1
The file structure is as follows:
<git root>/src/myPackage/Main.java
I have set the 'src' folder as the 'source folder'. My application has no compiler errors.
I have invalidated the caches several times, but with no effect whatsoever.
In my module settings my module dependencies contain <Module source> and jdk 1.8.
I can't seem to find the answer around here (google) anywhere, and to me it seems like this error has to do with the way IntelliJ handles the project. When I first pulled the project, the src folder had NOT been set to be the source folder, which probably means I may be missing out on other settings as well.
Zack Newsham's suggestion helped me. Here is what I did:
Deleted .iml file
File > New > Project, specified the existing folder with code
completed project setup (Manifest, artifacts).
Now the project runs.
Of course there may be other reasons for ClassNotFound. However when everything seems ok or if the error comes up after it worked before, try these simple steps.

Categories

Resources