Error NoClassDefFoundError

4

When I try to open the program it does not find the nativehook class, but it is in the classpath

Error:

C:\Users\Paulo\Desktop>java -jar AutoClick.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: org/jnativehook/keyboard/NativeKeyListener
            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.jnativehook.keyboard.NativeKeyListener
            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

C:\Users\Paulo\Desktop>pause
Pressione qualquer tecla para continuar. . .

.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
        <accessrules>
            <accessrule kind="nonaccessible" pattern="&quot;sun/**&quot;"/>
        </accessrules>
    </classpathentry>
    <classpathentry kind="lib" path="libs/JNativeHook.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

Manifest.mf

Manifest-Version: 1.0
Main-Class: com.pauloabr.AutoClicker.AutoClicker

I need to put something else in manifest.mf ?

This error appears when I execute in cmd, when I execute directly in the jar it appears "java exception has ocurred."

    
asked by anonymous 03.03.2015 / 17:57

3 answers

1

More details at this link: link

Basically, there is no official way to load classes from a JAR that is inside another JAR. There is a very old RFE (since 2002) about this, but it has never left the place: link

That said, you'll need some other kind of solution that involves or "blowing" the internal JAR into the outer JAR, then putting everything directly into the outer JAR, or getting a specialized%% or writing your own.

If you choose to use a specialized% wizard, among the suggestions raised in the English StackOverflow question linked at the beginning of this answer, we have JarClassLoader and One-Jar .

    
03.03.2015 / 21:09
0

Instead of:

java -jar AutoClick.jar

Try:

java -cp ./libs/JNativeHook.jar -jar AutoClick.jar
    
03.03.2015 / 18:01
0

Add the following line to your manifest.mf :

Class-Path: libs/JNativeHook.jar

Perhaps, the following may also work to load a JAR within the other, depending on how it is organized internally:

Class-Path: ./JNativeHook.jar

Or else:

Class-Path: ./libs/JNativeHook.jar
    
03.03.2015 / 19:04