Im trying to decrypt the value of an database on which i have access on.
The password is crypted via Windows API. So my thought was ok. Lets just try then to decrypt it the same way!
Im using Java 1.8.0_60 with JNA-platform.jar...
while (results.next()) {
String address = results.getString("value1");
String username = results.getString("value2");
String password = new String(Crypt32Util.cryptUnprotectData(results.getBytes("value_which_is_crypted")));
list.add(new String[] { value1,value2,value_which_is_crypted });
}
However, if im trying to execute my code im getting an ClassNotFoundException!
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Structure
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 com.sun.jna.platform.win32.Crypt32Util.cryptUnprotectData(Crypt32Util.java:121)
at com.sun.jna.platform.win32.Crypt32Util.cryptUnprotectData(Crypt32Util.java:103)
at com.sun.jna.platform.win32.Crypt32Util.cryptUnprotectData(Crypt32Util.java:90)
at recover.Chrome.recover(Chrome.java:35)
at recover.Chrome.main(Chrome.java:49)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Structure
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)
... 17 more
I hope this is enough information because this clearly gave me a headache.
Thanks for help!
EDIT:
ok lesson learned.. when using jna include both jna.jar and jna-platform.jar >in your buildpath! Thanks for your help!
You also need jna.jar in the classpath - com/sun/jna/Structure.class is in that jar.
Related
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.
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.
This question already has answers here:
What does "Could not find or load main class" mean?
(61 answers)
Closed 7 years ago.
I know this has been asked many times but I can't figure it out. :(
I have a big project and the structure is like:
Project - build
- Config
- src
- tst
- build.xml
- webapp
- eclipse-bin
There is a java file under tst/com/myspace/gateway/content/restlet/SanityTest.java
In the java file:
package com.myspace.gateway.content.restlet;
...
public class SanityTest extends ContentGatewayRestletResourceTestCase {
...
public static void main() {
}
}
After the whole project compiles, the class file of SanityTest is under build/private/classes/tests/com/myspace/gateway/content/restlet/SanityTest.class
I went into build/private/classes/tests and ran "java -cp . com.myspace.gateway.content.restlet.SanityTest" but got the NoClassDefFoundError.
Please help me!
PS:
Stack trace:
Exception in thread "main" java.lang.NoClassDefFoundError: com/myspace/gateway/content/ContentGatewayTestCase
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$000(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.ClassLoader.loadClassInternal(Unknown Source)
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$000(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.ClassLoader.loadClassInternal(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.myspace.gateway.content.ContentGatewayTestCase
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.ClassLoader.loadClassInternal(Unknown Source)
... 24 more
Could not find the main class: com.myspace.gateway.content.restlet.SanityTest. Program will exit.
You ran
java -cp . com/myspace/gateway/content/restlet/SanityTest
You should have run:
java -cp . com.myspace.gateway.content.restlet.SanityTest
Read this Q&A for more details:
What does "Could not find or load main class" mean?
UPDATE
According to the stacktrace, the problem is that Java cannot find the ContentGatewayTestCase class. Presumably, that is a class that your SanityTest class depends on. However, the source code snippet shows that SanityTest extends ContentGatewayRestletResourceTestCase. You need to figure out if the ContentGatewayTestCase dependency is correct:
If it is, the corresponding ".class" file needs to be in the same directory as your "SanityTest.class" file.
Either way, you probably have a problem with the way you are compiling your code.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
at org.apache.catalina.util.LifecycleBase.<clinit>(LifecycleBase.java:36)
Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
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)
I was trying to create wsag4j agreement service and I got this error.
You need to add apache logging library to your classpath.
You can download the library here and here you can get instructions on how to add it to classpath.
I tried out the tene tutorial of peter friese. For those who don't know what im talking about here's a link to it: http://www.peterfriese.de/using-teneo-and-emf-to-store-your-data/
I followed all steps till the end but after that i ran into a no class def found error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/emf/teneo/hibernate/HbMapperException
at library.main.LibraryDemo.main(LibraryDemo.java:21)
Caused by: java.lang.ClassNotFoundException: org.eclipse.emf.teneo.hibernate.HbMapperException
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)
... 1 more
I already added the required library as a dependency. So it should be a runtime issue.
Has anyone an idea?
You have to add org.eclipse.emf.teneo.hibernate.mapper.jar , you can download it from here