Noclassdeffounderror

Asked

Viewed 697 times

5

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 on manifest.mf?

This error appears when executed in cmd, when executed directly in the jar appears "java Exception has ocurred."

  • Yeah, and he’s in.

3 answers

1


More details on this link: https://stackoverflow.com/questions/183292/classpath-including-jar-within-a-jar

Basically, there is no official way to load the classes of a JAR that is inside another JAR. There is an RFE (request for Enhancement) well old (since 2002) about it, but never left the place: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4648386

That being said, you will need some other type of solution that involves either "blowing up" the internal JAR inside the external JAR, then putting everything directly into the external JAR, or else getting one ClassLoader specialized or write your own.

If you choose to use one ClassLoader specialized, among the suggestions raised in the Stackoverflow question in linked English at the beginning of this answer, we have the Jarclassloader and the One-Jar.

0

Instead of:

java -jar AutoClick.jar

Try:

java -cp ./libs/JNativeHook.jar -jar AutoClick.jar
  • This works, but only if I open by cmd, I want to open directly by . jar

0

Add to your manifest.mf the following line:

Class-Path: libs/JNativeHook.jar

Perhaps the following can also work to load one JAR into the other, depending on how it is organized internally:

Class-Path: ./JNativeHook.jar

Or else:

Class-Path: ./libs/JNativeHook.jar
  • It even works, but only if you have the libs/Jnativehook.jar folder on the same level as . jar, you can’t catch what’s inside the libs of . jar?

  • @pauloabr Edited. See if now it works.

  • didn’t work :/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.