0

web.xml ファイルがあり、プロパティ ファイルから複数の値を web.xml に読み込みたいと考えています。これは可能ですか?. はいの場合、どのように?.Javaクラス自体でこのプロパティファイルにアクセスできますか? 私は特に ant を使用してプロジェクトを構築しています。これに関するヘルプは大歓迎です。

4

2 に答える 2

3

プレースホルダーを使用してそれを行うことができます。例 (Gradle を使用):

gradle.properties:

myProp1=abc
myProp2=def

build.gradle:

war {
    eachFile {
        if (it.name == 'web.xml') {
            it.filter {String line -> line.replaceAll('\\$\\{textToReplace1\\}', myProp1) }
            it.filter {String line -> line.replaceAll('\\$\\{textToReplace2\\}', myProp2) }
        }
    }
}
于 2012-10-22T08:49:33.170 に答える
0
    properties.load(Connector.class.getResourceAsStream("path/to/properties/file"));

        this.DRIVER_CLASS = properties.getProperty("attribute/mentioned/in/the/property/file");
        this.DATABASE_URL = properties.getProperty("another/attribute/mentioned/in/the/property/file");
        this.databaseName = properties.getProperty("other/attribute/mentioned/in/the/property/file");
        this.username = properties.getProperty("other/attribute/mentioned/in/the/property");

    And so on...

プロパティ ファイルは、上記の「Cengiz」と同じ形式です。ここで this.variables は私のプライベート変数で、何でもかまいません。また、プロパティ ファイルは、クラスの階層の最上位にある必要があります。

これは私のクエリを解決しました。お手伝いありがとう。

于 2012-10-23T06:21:05.427 に答える