Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoClassDefFoundError: com/sun/jna/platform/win32/Shell32 #2

Closed
erayerdin opened this issue Nov 8, 2017 · 12 comments
Closed
Assignees
Milestone

Comments

@erayerdin
Copy link

I am using appdirs in a JavaFX application. appdirs throws exception in Windows 7 as below:

Exception in thread "JavaFX Application Thread" Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.NullPointerException
        at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:383)
        at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
        ... 5 more
java.lang.NoClassDefFoundError: com/sun/jna/platform/win32/Shell32
        at net.harawata.appdirs.impl.ShellFolderResolver.resolveFolder(ShellFolderResolver.java:38)
        at net.harawata.appdirs.impl.WindowsAppDirs.getLocalAppData(WindowsAppDirs.java:71)
        at net.harawata.appdirs.impl.WindowsAppDirs.getUserDataDir(WindowsAppDirs.java:33)
        at net.harawata.appdirs.AppDirs.getUserDataDir(AppDirs.java:28)
        at com.erayerdin.corpustk.App.<clinit>(App.java:19)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$155(LauncherImpl.java:352)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformI
mpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.platform.win32.Shell32
        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)
        ... 16 more

It works in Linux, though. Adding com.sun.jna as a Maven dependency does not work as well.


Environment

  • Microsoft Windows [Version 6.1.7601] (stands for Windows 7)
  • Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
  • Appdirs 1.0.0
@harawata
Copy link
Owner

harawata commented Nov 8, 2017

Hi @erayerdin ,

com.sun.jna seems to be very old.
Could you try adding the following dependency if you haven't?

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>4.5.0</version>
</dependency>

@erayerdin
Copy link
Author

Yeah, I also saw that. I hesitated to try it since the library specifically calls com.sun.jna, not net.java.dev.jna.

However, I will give it a try and post the results here.

@erayerdin
Copy link
Author

erayerdin commented Nov 8, 2017

Update: I was right. The same error occurs. My debug log below:

Exception in thread "JavaFX Application Thread" Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.NullPointerException
        at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:383)
        at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
        ... 5 more
java.lang.NoClassDefFoundError: com/sun/jna/platform/win32/Shell32
        at net.harawata.appdirs.impl.ShellFolderResolver.resolveFolder(ShellFolderResolver.java:38)
        at net.harawata.appdirs.impl.WindowsAppDirs.getLocalAppData(WindowsAppDirs.java:71)
        at net.harawata.appdirs.impl.WindowsAppDirs.getUserDataDir(WindowsAppDirs.java:33)
        at net.harawata.appdirs.AppDirs.getUserDataDir(AppDirs.java:28)
        at com.erayerdin.corpustk.App.<clinit>(App.java:19)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$155(LauncherImpl.java:352)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.platform.win32.Shell32
        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)
        ... 16 more

I will, still again, check my code to see if there is a mistake I've been doing (oddly, it works on Ubuntu even if there is a mistake).

@harawata
Copy link
Owner

harawata commented Nov 8, 2017

That error means your application could not find jna-4.5.0.jar in the classpath.
It occurs when, for example, the application is built with some incorrect build setting.

First, please make sure that jna-4.5.0.jar is included in your final JavaFX application.
If your application is a single .jar file, unpack it with jar -xvf or change the extension to .zip and unzip it.

If jna-4.5.0.jar is included and you still get the error, there might be something wrong with the application's MANIFEST.MF.
See if jna-4.5.0.jar is listed in JavaFX-Application-Class.

If the above does not help, please let me know how you build your JavaFX application (i.e. using IDE? mvn command?, etc.).

p.s.
JNA is used only on Windows, so it is not surprising that it works on Ubuntu.

@erayerdin
Copy link
Author

erayerdin commented Nov 8, 2017

Project already uses Maven, so it configures the classpath well. The project is here (I didn't push commits, so the lines you might check out in the project are old.).

I redefined application data folders manually temporarily, so my problem is kind of solved. These debug logs are all I have, but if I manage to find any further resources (like debug logs, code lines et cetera), I will give further information.

Edit

These lines where I initialize appdirs threw exception, so I commented it out.

@harawata
Copy link
Owner

harawata commented Nov 8, 2017

You seem to be using IntelljiJ as your IDE.
I'm not familiar with it at all, but open Project Settings -> Modules -> Dependencies and see if 'Export' is checked for the JNA library.

@zak-pawel
Copy link

@erayerdin
You need not only dependency to jna, but also to jna-platform.

Probably this should solve your problem:

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>4.5.0</version>
</dependency>
<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna-platform</artifactId>
    <version>4.5.0</version>
</dependency>

@erayerdin
Copy link
Author

@zak-pawel and @harawata
First, thanks for your quick response and focusing on this problem. However, due to my time limitation, I stopped utilizing this library in my project and patched manually by checking user.home stuff and so.

Since I dropped the library, I cannot give you further detail. Yet again, Maven is also a dependency management tool apart from building tool, so the configuration of this project must provide other dependencies and then be updated in Maven repository. Please, don't get me wrong. This is not an advice, this is just a suggestion from a random stranger on the internet.

This is the only library in Java and Maven repository utilizing crossplatform application directory management. I hope someone else will have the problem and can give you further details right after implementing your explanations.

Thanks again and I am sorry I could not continue using this library and give you enough feedback since I don't have enough time.

@zak-pawel
Copy link

@erayerdin
I'm not co-author of this library. I'm just a random stranger on the internet who had the same problem as you and found a workaround for this issue.

I totally agree that configuration of this project should provide other dependencies and I hope that @harawata fixes this dependency issue.

@harawata
Copy link
Owner

@erayerdin ,

No worries. I appreciate you took the time to report this!

@zak-pawel is right (thanks for the help!). I checked the dependency and it is jna-platform that is required by appdirs (jna is also required, but it will be automatically added because jna-platform depends on it).

Anyway, to make things simpler, I have modified the scope of jna-platform dependency to compile and released 1.0.1.

harawata added a commit that referenced this issue Nov 15, 2017
@zak-pawel
Copy link

I can confirm that 1.0.1 solves problem.
Thanks!

@harawata harawata self-assigned this Nov 16, 2017
@harawata harawata added this to the 1.0.1 milestone Nov 16, 2017
@harawata
Copy link
Owner

@zak-pawel Thank you for verifying it!
I believe we can close this issue.

ItaloYeltsin added a commit to TotalCross/totalcross that referenced this issue Sep 25, 2020
update appdirs library from 1.0.0 to 1.2.0 to avoid the
following bug:

harawata/appdirs#2
acmlira pushed a commit to TotalCross/totalcross that referenced this issue Sep 28, 2020
update appdirs library from 1.0.0 to 1.2.0 to avoid the
following bug:

harawata/appdirs#2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants