Skip to content

Commit

Permalink
Merge pull request #288 from alcarraz/287-db-properties-from-classpat…
Browse files Browse the repository at this point in the history
…h-resource

Let database properties be loaded from classpath.
  • Loading branch information
ar authored Oct 27, 2023
2 parents 8c47d70 + 939be2f commit 65d0322
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions modules/dbsupport/src/main/java/org/jpos/ee/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,16 @@ private Element readMappingElements(String moduleConfig) throws DocumentExceptio

private Properties loadProperties(String filename) throws IOException {
Properties props = new Properties();
final String s = filename.replaceAll("/", "\\" + File.separator);
final File f = new File(s);
if (f.exists()) {
try (FileReader fr = new FileReader(f)) {
props.load(fr);
if (filename.startsWith("jar:") && filename.length()>4) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
props.load(cl.getResourceAsStream(filename.substring(4)));
} else {
final String s = filename.replaceAll("/", "\\" + File.separator);
final File f = new File(s);
if (f.exists()) {
try (FileReader fr = new FileReader(f)) {
props.load(fr);
}
}
}
return props;
Expand Down

0 comments on commit 65d0322

Please sign in to comment.