Search code examples
javamavennoclassdeffounderror

axet/desktop: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform


I'm build project from repository https://github.com/axet/desktop/tree/master/java. And i'm trying to run DesktopTest class. I do that:

$ mvn package
$ cd target
$ java -cp ./desktop-2.3.3.jar:.:test-classes/ com.github.axet.desktop.DesktopTest
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform
        at com.github.axet.desktop.Desktop.getDesktopFolders(Desktop.java:53)
        at com.github.axet.desktop.Desktop.getHomeFolder(Desktop.java:32)
        at com.github.axet.desktop.DesktopTest.main(DesktopTest.java:10)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform
        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)

What i doing wrong?

Java version:

$ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Solution

  • You have not downloaded the dependencies for the package. They are listed in the pom.xml file. But you should not have to worry about doing that manually.

    Instead of simply using mvn package you should execute:

    $ mvn clean dependency:copy-dependencies package
    

    That will copy all the needed jars into the target/dependency directory. Add that directory to your classpath and it should work, e.g.,

    $ java -cp ./desktop-2.3.3.jar:.:test-classes/:dependency/* com.github.axet.desktop.DesktopTest