Ubuntu 上 Java 应用程序的权限
我有一个当前在 Windows 上运行的 NetBeans RCP 应用程序,我正在尝试使 Linux 兼容。该应用程序创建文件夹和文件并修改文件。
它在 Windows 上运行良好,无需任何修改,但在 Ubuntu 上,它无法在启动过程中创建文件夹。我知道这是一个权限问题。
我有什么选择?
应用程序本身是否可以像使用 ProcessBuilder 运行脚本一样分配所需的权限?
提前致谢!
I have a NetBeans RCP application that's currently working on Windows and I'm trying to make Linux compatible. The application creates folders and files and modify files as well.
It works fine on Windows without any modification but on Ubuntu it fails creating folders during start up. I know it's a permission issue.
What are my options?
Can the application itself assign the permissions it needs like by running a script using ProcessBuilder?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这完全取决于您在 Ubuntu 上运行该进程时的身份,以及您尝试创建的文件夹的路径。该用户是否有权在该目录中创建文件夹?您要写入磁盘的数据类型是什么?您可以使用面向用户的平台中立机制,例如 Java 首选项或者可能:
System.getProperty(“user.home”
)-或者-
System.getProperty("java.io.tmpdir")
?It all depends on who you are when running the process on Ubuntu, and the path of the folders that you're trying to create. Does this user have permissions to create the folders in that directory? What sort of data are you writing out to disk? Can you use a platform neutral mechanism thats user oriented, like Java Preferences or perhaps:
System.getProperty("user.home"
)-or-
System.getProperty("java.io.tmpdir")
?您需要在设置过程中创建所需的文件夹,或者将 IO 限制为您有权访问的文件夹(用户主文件夹和临时文件夹)。请注意,在 Linux 上有许多文件夹应放置的标准位置,并且管理员会对不遵循这些标准的应用程序感到不满。
您能说出您需要哪些文件/文件夹用于什么目的吗?
看起来问题的原因是 Windows 和 Linux 之间的路径分隔符不同。在 Linux 上你应该使用普通的斜杠。该错误提到了路径:
由于 \ 不是路径分隔符而是转义字符,因此它尝试在没有权限的文件夹 /home 中创建文件。
路径应该是:
您可能需要考虑将应用程序文件放入名为 .yourappname 的子文件夹中,这样它就会变成
这就是许多 UNIX 应用程序所做的并将其隐藏在正常文件列表中。要获取应用程序运行所在系统的路径分隔符,您可以使用以下静态字段:
You either need to create required folders as part of a setup process or restrict your IO to folders you have access to (the users home and the temp folder). Notice that on Linux there are standard locations where many folders should be placed and that administrators will frown upon applications that do not follow these standards.
Can you tell what files/folders you need for what purpose?
Looks like the cause of the problem is the difference in path delimiter between Windows and Linux. On linux you should use normal slashes. The error mentions the path:
As the \ is not a path delimiter but the escape character it is trying to create a file in the folder /home where it does not have permissions.
The path should be:
You might want to consider putting your apps files in a subfolder called .yourappname so then it would become
This is what many unix applications do and hide it in normal file listings. To get the path seperator for the system your application is running on you can use the following static field: