Ubuntu上Java应用程序的权限

时间:2022-05-29 11:42:50

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.

我有一个NetBeans RCP应用程序,目前正在Windows上工作,我正在努力使Linux兼容。该应用程序还创建文件夹和文件以及修改文件。

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.

它在Windows上运行正常,没有任何修改,但在Ubuntu上它无法在启动时创建文件夹。我知道这是一个许可问题。

What are my options?

我有什么选择?

Can the application itself assign the permissions it needs like by running a script using ProcessBuilder?

应用程序本身是否可以通过使用ProcessBuilder运行脚本来分配所需的权限?

Thanks in advance!

提前致谢!

2 个解决方案

#1


0  

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:

这一切都取决于您在Ubuntu上运行进程时的身份,以及您尝试创建的文件夹的路径。该用户是否有权在该目录中创建文件夹?你在写什么类型的数据到磁盘?您是否可以使用面向用户的平台中立机制,例如Java Preferences或者:

System.getProperty("user.home") -or- System.getProperty("java.io.tmpdir")?

System.getProperty(“user.home”) - 或 - System.getProperty(“java.io.tmpdir”)?

#2


0  

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.

您需要在安装过程中创建所需的文件夹,或将IO限制为您有权访问的文件夹(用户主页和临时文件夹)。请注意,在Linux上有标准位置,应放置许多文件夹,管理员会对不遵循这些标准的应用程序不满意。

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:

看起来问题的原因是Windows和Linux之间路径分隔符的差异。在linux上你应该使用普通的斜杠。该错误提到了路径:

/home/javier\marauroa.trace.db

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.

因为\不是路径分隔符,而是转义字符,它试图在文件夹/ home中创建一个没有权限的文件。

The path should be:

路径应该是:

/home/javier/marauroa.trace.db

You might want to consider putting your apps files in a subfolder called .yourappname so then it would become

您可能需要考虑将您的应用程序文件放在名为.yourappname的子文件夹中,这样就可以了

/home/javier/.yourappname/marauroa.trace.db

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:

这是许多unix应用程序所做的事情,并将其隐藏在普通文件列表中。要获取运行应用程序的系统的路径分隔符,可以使用以下静态字段:

java.io.File.seperator

#1


0  

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:

这一切都取决于您在Ubuntu上运行进程时的身份,以及您尝试创建的文件夹的路径。该用户是否有权在该目录中创建文件夹?你在写什么类型的数据到磁盘?您是否可以使用面向用户的平台中立机制,例如Java Preferences或者:

System.getProperty("user.home") -or- System.getProperty("java.io.tmpdir")?

System.getProperty(“user.home”) - 或 - System.getProperty(“java.io.tmpdir”)?

#2


0  

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.

您需要在安装过程中创建所需的文件夹,或将IO限制为您有权访问的文件夹(用户主页和临时文件夹)。请注意,在Linux上有标准位置,应放置许多文件夹,管理员会对不遵循这些标准的应用程序不满意。

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:

看起来问题的原因是Windows和Linux之间路径分隔符的差异。在linux上你应该使用普通的斜杠。该错误提到了路径:

/home/javier\marauroa.trace.db

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.

因为\不是路径分隔符,而是转义字符,它试图在文件夹/ home中创建一个没有权限的文件。

The path should be:

路径应该是:

/home/javier/marauroa.trace.db

You might want to consider putting your apps files in a subfolder called .yourappname so then it would become

您可能需要考虑将您的应用程序文件放在名为.yourappname的子文件夹中,这样就可以了

/home/javier/.yourappname/marauroa.trace.db

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:

这是许多unix应用程序所做的事情,并将其隐藏在普通文件列表中。要获取运行应用程序的系统的路径分隔符,可以使用以下静态字段:

java.io.File.seperator