Warning: Use of undefined constant id - assumed 'id' (this will throw an Error in a future version of PHP) in /kunden/247608_14469/webseiten/wp-content/themes/wordblab/functions.php on line 28
Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /kunden/247608_14469/webseiten/wp-content/themes/wordblab/functions.php on line 29
Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /kunden/247608_14469/webseiten/wp-content/themes/wordblab/functions.php on line 9
Wer in einem Java EE Webprojekt die beliebten Properties verwenden will, der muss dafür sorgen, dass beim Build-Prozess die entsprechenden Dateien in den Klassenpfad (target/classes) mit aufgenommen werden.
Um das zu bewerkstelligen, kann man eine Datei namens settings.properties im Resource-Ordner der Source Packages (src/main/resources) anlegen. Hat man das getan, muss man in der pom.xml seines Maven Webprojektes (siehe siehe Java EE Web Application erstellen) noch angeben, dass alle Dateien aus diesem Ordner bei einem Build in den Classpath gelegt werden:
Auszug aus pom.xml
... <build> <resources> <resource> <directory>src/main/resources</directory> </resource> </resources> <plugins> ... </plugins> ... |
Nach diesen Einstellungen, kann man die Properties-Datei in seinem Code verwenden:
Beispiel
// load properties InputStream in = this.getClass().getResourceAsStream("/settings.properties"); Properties properties = new Properties(); properties.load(in); in.close(); // use properties String userAccount = properties.getProperty("user.account"); |