感谢@PeterNiederwieser,我解决了我的问题:
在我的gradle.build中,我使用:
task usernameMaxio(type: Copy) {
from 'src/main/resources/properties'
into 'build/resources/main/properties'
expand([
username: 'Maxio'
])
}
我通过以下方式访问它:
Properties properties = new Properties();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream stream = loader.getResourceAsStream("properties/app.properties");
try {
properties.load(stream);
} catch (IOException | NullPointerException e) {
WebOptionPane.showMessageDialog(null, "Couldn't read app.properties", "Fehler",
WebOptionPane.ERROR_MESSAGE);
e.printStackTrace();
return;
}
name = properties.getProperty("username");
在我的app.properties中:
username=${username}