简体   繁体   English

Java:无需管理员权限即可在何处编写配置

[英]Java: Where to write config without requiring administrative rights

I actually can't believe I'm saying this but since porting my programs to OSX and getting used to permissions, I've realized that what I planned to do on Windows will not work how I want it to. 我实际上不敢这么说,但是由于将程序移植到OSX并习惯了权限,所以我意识到我计划在Windows上执行的操作无法达到我的期望。 Currently, on windows, my program stores it's setting's in the registry (HKLM) and some user editable resources in a folder next to the program file. 当前,在Windows上,我的程序将其设置存储在注册表(HKLM)中,并将一些用户可编辑的资源存储在程序文件旁边的文件夹中。 For various reasons, I have now decided that the configuration/settings will be stored in a file and the user will be able to in which folder the other resources are kept. 由于各种原因,我现在决定将配置/设置存储在文件中,并且用户将能够将其他资源保存在哪个文件夹中。

So the question I have now is where to store the configuration file. 所以我现在的问题是在哪里存储配置文件。 Obviously it will be updated, but I don't want to program to have to require administrator permissions to run. 显然它将被更新,但是我不想编程来必须要求管理员权限才能运行。 I would like to offer an option so that all users can use the program (like most programs do), which will of course require Admin, so this leads be onto the second query: where should I store the configuration file (and the folder in which other resources are kept) and how can I detect whether the program has been installed for all users or just one! 我想提供一个选项,以便所有用户都可以使用该程序(就像大多数程序一样),这当然需要Admin,因此这引出了第二个查询:我应该在哪里存储配置文件(和文件夹中的文件夹)保留了哪些其他资源)以及如何检测是否已为所有用户或仅一个用户安装了该程序!

Thanks in advance 提前致谢

PS If you didn't guess, the program is written in Java so I would like to know how to programatically get the location you suggest as well please. PS:如果您没有想到,该程序是用Java编写的,因此我想知道如何以编程方式获取您建议的位置。

Its normal practice in *nix compatible programs to store information in folders starting with name . * nix兼容程序的常规做法是将信息存储在以name开头的文件夹中。 in the home directory of the users like, 在用户的主目录中,

.bash_history
.bashrc

You could use the same on OSX in my opinion and create a directory say, 我认为您可以在OSX上使用相同的文件,并创建一个目录,例如:

.myapp

You can store any number of files with any format under that directory. 您可以在该目录下存储任意数量的任何格式的文件。

To get the location of the folder, you can do 要获取文件夹的位置,您可以

String homeDir = System.getProperty("user.home");
File myAppDir = new File(homeDir, ".myapp");

That is roughly the code that can get you your custom config directory for your app. 这大致就是可以为您的应用程序提供自定义配置目录的代码。

Please not that dot files / folders are somewhat similar to hidden folders in windows. 请不要让点文件/文件夹与Windows中的隐藏文件夹有些相似。 Your File Manager will not generally show these files / folders by default. 默认情况下,文件管理器通常不会显示这些文件/文件夹。

To identify if the program is installed for all the users or not, you could create the configuration at some administrator (root) controlled location like /etc (not sure about Mac) The user configuration can always override the default config. 要确定是否为所有用户安装了该程序,可以在一些管理员(根)控制的位置(例如/ etc)(对于Mac不确定)创建配置。用户配置始终可以覆盖默认配置。 There could be a better way to handle this though. 不过,可能有更好的方法来处理此问题。

On both windows and unix, User(usually) has a (home)folder to which it has full permissions. 在Windows和Unix上,用户(通常)都具有一个(家庭)文件夹,该文件夹具有完全权限。 You may create a directory in the home folder and have your user configuration files reside there. 您可以在主文件夹中创建目录,并将用户配置文件放置在该目录中。

暂无
暂无

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

相关问题 Java与LDAP:在没有管理权限的情况下更改用户密码吗? - Java with LDAP: change users password without administrative rights? 在Java Web应用程序中将UI配置存储在何处以及从jsp页面读写配置文件的位置 - Where to store UI config in a java web app and read-write the config file from jsp page 从PHP / Java / Python Web应用程序调用shell命令(包括那些需要root权限的命令)的正确方法是什么? - What are the right ways to call shell commands (incl. those requiring root rights) from PHP/Java/Python web applications? 使用不带sudo权限的java重新启动运行ubuntu的计算机? - Restart a computer running ubuntu using java without sudo rights? 在没有管理员权限的情况下更改 Windows 10 中的 Java_Home 路径 - Change Java_Home Path in windows 10 without admin rights 如何在不需要安装 jdk 或 jre 的情况下运行 java 程序 - How to run a java program without requiring jdk or jre to be installed 使用Java Futures而不要求本地可变状态 - Using java futures without requiring local mutable state Java中的组播,无需目标主机加入该组 - Multicast in java without requiring destination hosts to join the group 有没有一种方法可以在不需要专用服务器的情况下使用 Java 存储信息? - Is there a a way I can store information with Java without requiring a dedicated server? 无需受保护资源即可进行JSF / Java EE登录 - JSF / Java EE login without requiring a protected resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM