harawata / appdirs Goto Github PK
View Code? Open in Web Editor NEWA small utility that provides cross platform access to the special folders/directories like application data.
License: Apache License 2.0
A small utility that provides cross platform access to the special folders/directories like application data.
License: Apache License 2.0
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.
Shouldn't it point to Library/Preferences instead of Library/Application Support?
Since the preferences folder isn't removed when the application is uninstalled and can be migrated when upgrading the Mac, I think it makes sense to store user configuration inside this folder instead of Application Support, that is also available using DataDir.
Hello !
Thank you for wonderfull library. But I can't make it work.
Firstly I added library into pom.xml of my project the latest version of library.
**
net.harawata
<artifactId>appdirs</artifactId>
<version>1.2.1</version>
**
But when I try to write into class this library my project dosn't see (I was wondering how).
When I pay attentiong that this library include of in maven but not showing in maven toolbar that has in intellij idea in left toolbar.
If you see below. You could see all dependecies that written in pom xml has in left toolbar but not AppDirs library. Please could you help me to figure it out about it. How I could make to show up this library in my project
Thanks in advance
Seems like the original Python module got updated and now allows to pull even more useful directories! Would be amazing to have it on Java platform as it seems like there's no library that can do it yet.
As reported in http://msdn.microsoft.com/en-us/library/bb762181%28VS.85%29.aspx, the function is deprecated. Please, consider to change with new method or, better, validating the environment variables (here you can view a summary this: https://stackoverflow.com/a/39868933/5695585)
I'm using slf4j with logback. I created custom FileAppender and I wanted to select destination of log file using appdirs. Unfortunately the lib uses the logging itself so it became an circular dependency - my appender needs appdirs, appdirs needs logging and logging needs my appender. Not sure how to address this issue.
Each OS has different temp directory. It would be good to have such functionality.
You have many patterns, but too many parameters aren't optional, and I don't want to use version and appAuthor.
Especially version may make no sense if an app wants to find the existing data after an upgrade, and continue using it....
Hello,
i am really missing a library like this for jvm development.
I am used to using the appdirs module in python.
Would you mind publishing this library as a jar to maven central or some comparable repository?
It would help us a lot!
This very much relates to #4
I'm trying to use AppDirs to set my log file directory, but AppDirs using a logger itself makes this very difficult as it loads my logger before I am able to set my logging directory system property to a path obtained by AppDirs.
If you want to keep logging in AppDirs (Which at this time is only used in ShellFolderResolver
and AppDirsFactory
), how about some method of obtaining an AppDirsFactory
with a disabled logger?
public class AppDirsFactory {
private static Logger logger;
private AppDirsFactory() {
super();
}
public static AppDirs getInstanceWithoutLogger() {
logger = NOPLogger.NOP_LOGGER;
return createInstance(false);
}
public static AppDirs getInstance() {
logger = LoggerFactory.getLogger(AppDirsFactory.class);
return createInstance(true);
}
private static AppDirs createInstance(final boolean logging) {
String os = System.getProperty("os.name").toLowerCase();
if (os.startsWith("mac os x")) {
// ...
} else if (os.startsWith("windows")) {
logger.debug("os.name {} is resolved to Windows", os);
// do the same in ShellFolderResolver
WindowsFolderResolver folderResolver = new ShellFolderResolver(logging);
return new WindowsAppDirs(folderResolver);
} else {
// ...
}
}
}
I realize this isn't super pretty, but I feel like something like this is much needed. Not creating a logger while trying to find out which directory to log to would improve this already excellent little library, and I feel like this must be a pretty common use case.
Java apps don't automatically have permission to write to /Library/Application Support/
It may be better to return /Users/Shared/ or /Users/Shared/Library/Application Support/ which automatically has permissions for all users.
Calling appDirs.getUserDataDir()
throws an Exception on Windows Server 2016 (and maybe other versions of Windows Server):
java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.Native
at com.sun.jna.platform.win32.Shell32.<clinit>(Shell32.java:32)
at com.sun.jna.platform.win32.Shell32Util.getFolderPath(Shell32Util.java:44)
at com.sun.jna.platform.win32.Shell32Util.getFolderPath(Shell32Util.java:61)
at net.harawata.appdirs.impl.ShellFolderResolver.resolveFolder(ShellFolderResolver.java:47)
at net.harawata.appdirs.impl.WindowsAppDirs.getLocalAppData(WindowsAppDirs.java:75)
at net.harawata.appdirs.impl.WindowsAppDirs.getUserDataDir(WindowsAppDirs.java:33)
at net.harawata.appdirs.AppDirs.getUserDataDir(AppDirs.java:20)
I was able to reproduce this exception on a new clean VM with just a Test-Application only calling this method. I tested with Java 9 and Java 14, both have the same Issue. I'm using the latest 1.2.0-Version.
On my Windows 10 System everything works fine.
Either I am missing something, or you read XDG variables in the wrong place.
XDG_DATA_HOME
, XDG_RUNTIME_DIR
, etc are environment variables. But you're trying to read them using System.getProperty
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.