简体   繁体   English

Java共享属性文件:Windows + Unix(通用)

[英]Java shared Property File: Windows + Unix (generic)

So, in my departement, we got an Java application (running on Unix) which can be parametrised by an .property File. 因此,在我所在的部门,我们得到了一个Java应用程序(在Unix上运行),该应用程序可以通过.property文件进行参数设置。 Inside this File, there are few refrences to other files (eg Log file path). 在此文件内,对其他文件的引用很少(例如,日志文件路径)。 Now, we need to use the same application on windows platforms. 现在,我们需要在Windows平台上使用相同的应用程序。 Everything works fine, until it should all be generic. 一切正常,直到应该通用为止。 So, we don't want to change anything except the .property file to make it run on both systems generic. 因此,我们不想更改.property文件以外的任何内容,以使其在两个系统上都通用。 But I don't really know how to handle this. 但是我真的不知道该如何处理。 On Unix, I need like environment variavles on unix but I know, Java can not resolve environment variables automatically. 在Unix上,我需要像Unix上的环境变量一样,但是我知道Java无法自动解析环境变量。 In windows its like the same. 在Windows中一样。 How would you solve this problem? 您将如何解决这个问题?

Add a property for each OS and then read accordingly on code 为每个操作系统添加一个属性,然后相应地阅读代码

# properties file
my.prop.nix=/some/unix/path
my.prop.win=c:\some \window$\path

Read OS on java with 使用读取Java上的OS

String OS = System.getProperty("os.name").toLowerCase();

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

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