質問

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?

役に立ちましたか?

解決 2

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top