Using XDG directory specification on Java application

↘锁芯ラ 提交于 2019-12-13 00:09:48

问题


I'm trying to follow XDG directory specification on my Java application. I have already used it for application data:

 protected String getDefaultDataDir() {

    String rootPath = System.getenv("XDG_DATA_HOME");

    if(rootPath == null) {
        rootPath = System.getProperty("user.home")+S+".local"+S+"share";
    }

    return rootPath+S+Pinocchio.PLATFORMNAME;
 }

( S is a constant containing System.getProperty("file.separator"))

I want now to store documents on the user documents' folder. But I don't have an environment variable named XDG_DOCUMENTS_DIR. I have the ".config/user-dirs.dirs" file that have that XDG configuration, and the "xdg-user-dir DOCUMENTS" which directly returns that path.

Making things worse, the default documents directory depends on the user locale.

Which is the best way to use the configured Documents directory on a java application?


回答1:


On Gnome there is java-gnome support library, it is doing native calls for better integration with gnome. It can get path of user dirs via calls to Glib.getUserSpecialDir. Haven't tried this one myself, might be worth a try if you are planning to use more desktop-integrated features in your program.




回答2:


While looking for an answer for this, I found xdg-java. I haven't tested it yet but seems to do exactly what you (and I) want.

It doesn't yet implement all the specifications but it does implement the ones I need for now and I would guess the author would be receptive to patches.



来源:https://stackoverflow.com/questions/22250118/using-xdg-directory-specification-on-java-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!