From 939be2f507b113e81a3b70db3e899d72a3c30df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alcarraz?= Date: Fri, 27 Oct 2023 14:34:08 -0500 Subject: [PATCH] Let database properties be loaded from classpath. Implements #287. --- .../dbsupport/src/main/java/org/jpos/ee/DB.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/dbsupport/src/main/java/org/jpos/ee/DB.java b/modules/dbsupport/src/main/java/org/jpos/ee/DB.java index 0d8f66844d..a8e09220f3 100644 --- a/modules/dbsupport/src/main/java/org/jpos/ee/DB.java +++ b/modules/dbsupport/src/main/java/org/jpos/ee/DB.java @@ -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;