2016-09-06 3 views
3

debug.properties私のプロジェクトにはデバッグ設定のファイルがあります。レポにあるこのファイルと各チームメイトは、デバッグする前にこのファイルを変更する必要があります。Cでのapp.configのようなjavaの.propertiesファイルを変換することは可能ですか

debug.template.propertiesファイルに基づいてこのファイルを修正してから、C#でxml変換するようにビルドすることはできますか?

答えて

1

あなたがcfg4jライブラリと次のコードを使用することができます。

private ConfigurationProvider configureProvider() { 
    ClassLoader classLoader = getClass().getClassLoader(); 
    String envPath = classLoader.getResource("properties").getPath(); 
    Path localPropertiesFilePath = Paths.get(envPath, "local.properties"); 
    Path basePropertiesFilePath = Paths.get(envPath, "base.properties"); 

    if (!Files.exists(localPropertiesFilePath)) { 
     try { 
      Files.createFile(localPropertiesFilePath); 
     } 
     catch (IOException exception) { 
      exception.printStackTrace(); 
     } 
    } 

    ConfigFilesProvider localConfigFilesProvider = 
      () -> Collections.singletonList(localPropertiesFilePath); 
    ConfigFilesProvider baseConfigFilesProvider = 
      () -> Collections.singletonList(basePropertiesFilePath); 

    ConfigurationSource local = new FilesConfigurationSource(localConfigFilesProvider); 
    ConfigurationSource base = new FilesConfigurationSource(baseConfigFilesProvider); 
    // If you have 'some' property in base and local files - it takes from local 
    ConfigurationSource mergedSource = new MergeConfigurationSource(base, local); 

    Environment environment = new ImmutableEnvironment(envPath); 

    return new ConfigurationProviderBuilder() 
      .withConfigurationSource(mergedSource) 
      .withEnvironment(environment) 
      .build(); 
} 
関連する問題