try (InputStream is = getClass().getResourceAsStream("/test.properties")) {
Properties properties = new Properties();
properties.load(is);
ps=new PropertiesPropertySource("main", properties);
} catch (IOException e) {
log.error("Something went wrong", e);
}
private String getPomPerpertiesPath() {
String classPath = getClass().getClassLoader().getResource("").getPath();
String aString = "classes/";
String targetPath = classPath.substring(0, classPath.lastIndexOf(aString));
StringBuilder sb = new StringBuilder();
sb.append(targetPath).append("maven-archiver/pom.properties");
return sb.toString();
}*/
private Properties getProperties(InputStream is) throws IOException {
Properties properties = new Properties();
properties.load(is);
log.info("All defined properties: {}", properties);
return properties;
}
private Properties getProperties(String fileName) throws IOException {
try (InputStream is = new FileInputStream(new File(fileName))) {
Properties properties = new Properties();
properties.load(is);
log.info("All defined properties: {}", properties);
return properties;
}
System.out.println(getClass().getClassLoader().getResource(""));
System.out.println(getClass().getClassLoader().getResource("").getPath());
System.out.println(getClass().getResource(""));
System.out.println(getClass().getResource("").getPath());
file:/C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/
/C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/
file:/C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/com/citi/simpliciti/tempest/report/
/C:/Users/lt32806/git/tempest/tempest-app/tempest-app-report/target/classes/com/citi/simpliciti/tempest/report/
https://blog.csdn.net/wws921104/article/details/72637050/
http://riddickbryant.iteye.com/blog/436693