java.lang.ClassNotFoundException error - java

I've just reconfigured my Eclipse IDE.
And when I run my web application, I got this error
It seems that I miss this Jar, I placed it in my lib folder of my Dynamic Web Application but it doesn't work.
java.lang.ClassNotFoundException: com.sun.istack.localization.Localizable
java.net.URLClassLoader$1.run(Unknown Source)
java.net.URLClassLoader$1.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
java.net.URLClassLoader.defineClass(Unknown Source)
java.net.URLClassLoader.access$100(Unknown Source)
java.net.URLClassLoader$1.run(Unknown Source)
java.net.URLClassLoader$1.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
java.net.URLClassLoader.defineClass(Unknown Source)
java.net.URLClassLoader.access$100(Unknown Source)
java.net.URLClassLoader$1.run(Unknown Source)
java.net.URLClassLoader$1.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:208)
com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:112)
javax.xml.ws.Service.<init>(Unknown Source)
com.bh.services.client.ServiceService.<init>(ServiceService.java:41)
com.bh.servlets.Connexion.doPost(Connexion.java:35)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
IDE: Eclipse.
Local server: Tomcat 7.
Any help please?

After placing the jar file in the lib folder of your web-app, you also need to add that jar file to your 'Build Path'.
To check if the jar file is in your projects build path, in your project explorer window go to 'Java Resources' there should be two more menu items under it : 1.src and 2.Libraries.
check under Libraries if the jar file you added exists there or not.
If it doesn't exists, then in the lib folder where you actually stored the jar file, just right click on it then in the menu select Build Path and then 'Add to Build Path'.
Just it, you are done then.

Related

How to solve NoClassDefFoundException while junit test?

I want to use JUnit tester to my Java program, but I got java.lang.NoClassDefFoundException. As I read this may got if I don't have .class file. But, since first I use it with javac, as I think it must be there.
Here is my command line:
myComputer\java\bead2>javac -cp .;junit-4.12.jar;hamcrest-core-1.3.jar
snake\tests\ToApplesTest.java
myComputer\java\bead2>java -cp .;junit-4.12.jar;hamcrest-core-1.3.jar
org.junit.runner.JUnitCore snake\tests\ToApplesTest
JUnit version 4.12
Exception in thread "main" java.lang.NoClassDefFoundError: snake\tests\ToApplesTest (
wrong name: snake/tests/ToApplesTest)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.junit.internal.Classes.getClass(Classes.java:16)
at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandL
ineParseResult.java:100)
at org.junit.runner.JUnitCommandLineParseResult.parseArgs(JUnitCommandLinePar
seResult.java:50)
at org.junit.runner.JUnitCommandLineParseResult.parse(JUnitCommandLineParseRe
sult.java:44)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:72)
at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
Why this crashing for me?
Try snake.tests.ToApplesTest. You must provide a package name, not a path to the containing folder.

Java - JOGL deploy: NoClassDefFoundError

Dev env: ItelliJ 14 -> compiles and runs fine.
When executing my custom created .jar from command line this appears
C:\Java\Projects\OpenGLES\out\artifacts\Test1>java -jar Test1.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/jogamp/opengl/G
ventListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.jogamp.opengl.GLEventListener
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
I'm trying to create .jar artifact, that I could just double click start.
I think that the problem means that this class cannot find some resources. The JOGL/JogAmp official sites gives explanation on deployment of .jars with JOGL, but I think that I missed something.
The Test1.jar has following structure:
Test1.jar/
--com/
----company/
------Main.class
--jar/
----gluegen-rt.jar
----gluegen-rt-natives-windows-amd64.jar
----gluegen-rt-natives-windows-i586.jar
----jogl-all.jar
----jogl-all-natives-windows-amd64.jar
----jogl-all-natives-windows-i586.jar
--lib/
----windows-amd64/
-------gluegen-rt.dll
-------joal.dll
-------jocl.dll
-------jogl_cg.dll
-------jogl_deskop.dll
-------jogl_mobile.dll
-------nativewindow_awt.dll
-------nativewindow_win32.dll
-------newt.dll
-------soft_oal.dll
--META-INF/
----MANIFEST.MF
--com
--jar
--lib
--META-INF
manifest.mf contains -
Manifest-Version: 1.0
Main-Class: com.company.Main
By the stack trace it seems that the JVM cannot find the class com.jogamp.opengl.GLEventListener that means it can't resolve the path to the included jar files. The path of the jar files is not correct. Follow the link to see how to package jars correctly.
https://docs.oracle.com/javase/tutorial/deployment/jar/

Java exception error after exporting javafx jar

I have a javafx application that I've been developing in eclipse and it is working fine on the IDE. However, when I export it into a jar, I get the following Exception:
java.lang.NoClassDefFoundError: javafx/application/Application
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
Exception in thread "main"
I've even created a MainTerminal class that doesn't use javaFX, instead just interacts within the terminal and after I exported the jar using MainTerminal as the main class and it worked fine. It seems I'm not being able to export some dependency or something but I checked the buildpath and it seemed alright to me.
I feel quite dumb about this but I just found out what my problem was. I was exporting my project as a Jar instead of a runnable Jar, that's why it was throwing an exception when I tried executing it.

Java webstart stopped working after Java 7 update 45 for jcl-over-slfj4.jar

My application is using Java web start with JNLP. After installing all Java 7 related updates my application was running fine but when I added jcl-over-slf4j-1.1.1.jar file in the lib folder then my application stopped working. When I remove it the application worked fine again.
NOTE: This application is also using Log4j jar file.
Not sure if the issue is with this jar file or with my application.
Here is the corresponding stack trace for this issue:
java.lang.NullPointerException
at com.sun.jnlp.JNLPClassLoader.getPermissions(Unknown Source)
at java.security.SecureClassLoader.getProtectionDomain(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:272)
at org.apache.commons.configuration.AbstractFileConfiguration.(AbstractFileConfiguration.java:121)
at org.apache.commons.configuration.PropertiesConfiguration.(PropertiesConfiguration.java:222)

Error occurred while execute main calls on jar file

While I am running Main class related to Jar file I got following error. Some one please help me. Thanks.
D:\data\Gateway\dist>java -jar Gateway.jar com.Application
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/support/AbstractApplicationContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.support.AbstractApplicationContext
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
The message
java.lang.NoClassDefFoundError:
org/springframework/context/support/AbstractApplicationContext
indicates that the jar org.springframework.context must be added to the classpath.

Categories