简体   繁体   中英

Path variables on Linux and Windows

I had several path variables in a Java project, that worked fine on Linux. These variables are stored in the .properties file and are used in Spring application context. Here is an example of a name variable that works: just.an.example=/home/username/settings/ . Pretty straightforward, right? I'm trying to run this app on Windows machine. I tried the following: just.an.example=d:/settings/ , just.an.example=d\\:/settings/ , just.an.example=d\\:\\\\settings\\\\ , just.an.example=file:///d:/settings/ and a few more, none of which worked.

I get NullPointerException that is a reason of an attempt to use files taken from the folder (which made me think the folder can not be seen). To be more specific, these variables are used as parameters of the File class constructor. The rights to access folders are default, I just created them.

What is a working option for this example variable?

Update : It finally worked with just.an.example=D:/settings/ , somehow I had to reimport Maven project after reinstalling it, not only to update dependencies, but D:/settings/ works fine in this case.

If /home/username/settings/ is equivalent to D:/settings/ , the last would be correct. Forward slashes work fine for this and I have done this type of thing many times. If you can access D:/settings/ through Windows explorer, then Java should also be able to. Try pasting D:/settings/ in Windows explorer and see what happens.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM