简体   繁体   English

Linux和Windows上的路径变量

[英]Path variables on Linux and Windows

I had several path variables in a Java project, that worked fine on Linux. 我在Java项目中有几个路径变量,在Linux上运行良好。 These variables are stored in the .properties file and are used in Spring application context. 这些变量存储在.properties文件中,并在Spring应用程序上下文中使用。 Here is an example of a name variable that works: just.an.example=/home/username/settings/ . 这是一个有效的名称变量的示例: just.an.example=/home/username/settings/ Pretty straightforward, right? 很简单吧? I'm trying to run this app on Windows machine. 我正在尝试在Windows计算机上运行此应用程序。 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. 我尝试了以下操作: just.an.example=d:/settings/ just.an.example=d\\:/settings/ just.an.example=d\\:\\\\settings\\\\just.an.example=file:///d:/settings/和其他一些,都没有用。

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). 我得到NullPointerException,这是尝试使用从文件夹中获取文件的原因(这使我认为无法看到该文件夹​​)。 To be more specific, these variables are used as parameters of the File class constructor. 更具体地说,这些变量用作File类构造函数的参数。 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. 更新 :它最终与just.an.example=D:/settings/ ,以某种方式我必须在重新安装后重新导入Maven项目,不仅要更新依赖关系,而且D:/settings/在这种情况下也可以正常工作。

If /home/username/settings/ is equivalent to D:/settings/ , the last would be correct. 如果/home/username/settings/等效于D:/settings/ ,则最后一个正确。 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. 如果您可以通过Windows资源管理器访问D:/settings/ ,那么Java也应该可以。 Try pasting D:/settings/ in Windows explorer and see what happens. 尝试在Windows资源管理器中粘贴D:/settings/ ,看看会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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