URL url = TestingClass.class.getResource(JAR_DIRECTORY);
FileSystem fileSystem = FileSystems.newFileSystem(url.toURI(), Collections.<String, Object>emptyMap());
Path myPath = fileSystem.getPath(JAR_DIRECTORY);
PropertyUtil propertyUtil = ConfigurationManager.getBundle();
try (Stream<Path> walk = Files.walk(myPath, 1)) {
List<String> xmlFileNames = walk.map(x -> x.toString())
.filter(f -> f.endsWith(".xml")).collect(Collectors.toList());
xmlFileNames.forEach(System.out::println);
xmlFileNames.forEach(file -> {
URL urlFile = TestingClass.class.getResource(file.subString(1));
propertyUtil.load(urlFile);
}
} catch (IOException e) {
e.printStackTrace();
}
IllegralArgumentException: Passed in key must select exactly one node: requests.request1 on HierarchialConfiguration.java:588
public void loadResources(Class clazz, String folderName) {
List<String> files;
try {
files = IOUtils.readLines(clazz.getClassLoader().getResourceAsStream(folderName + "/"),
Charset.forName("UTF-8"));
if (files != null && !files.isEmpty()) {
for (String file : files) {
InputStream inputStream = SFListener.class.getClassLoader()
.getResourceAsStream(folderName + "/" + file);
AbstractConfiguration.setDefaultListDelimiter(';');
PropertiesConfiguration configuration = new PropertiesConfiguration();
configuration.load(inputStream);
ConfigurationManager.getBundle().copy(configuration);
}
} else {
Enumeration<URL> en = ElementUtils.class.getClassLoader().getResources(folderName);
if (en.hasMoreElements()) {
URL url = en.nextElement();
JarURLConnection urlcon = (JarURLConnection) (url.openConnection());
try (JarFile jar = urlcon.getJarFile();) {
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (entry.getName().startsWith(folderName) && !entry.isDirectory()) {
InputStream inputStream = jar.getInputStream(entry);
AbstractConfiguration.setDefaultListDelimiter(';');
PropertiesConfiguration configuration = new PropertiesConfiguration();
configuration.load(inputStream);
ConfigurationManager.getBundle().copy(configuration);
}
}
}
}
}
} catch (IOException | ConfigurationException e) {
e.printStackTrace();
}
}
Hi Amit,
Are these classes SFListener, ElementUtils , from any dependency or used defined?
On Sunday, August 16, 2020 at 11:50:38 PM UTC-5, Amit Bhoraniya wrote:
Below code works perfectly for me to load resources from classpath.
public void loadResources(Class clazz, String folderName) {
List<String> files;
try {
files = IOUtils.readLines(clazz.getClassLoader().getResourceAsStream(folderName + "/"),
Charset.forName("UTF-8"));
if (files != null && !files.isEmpty()) {
for (String file : files) {
InputStream inputStream = clazz.getClassLoader()
.getResourceAsStream(folderName + "/" + file);
AbstractConfiguration.setDefaultListDelimiter(';');
PropertiesConfiguration configuration = new PropertiesConfiguration();
configuration.load(inputStream);
ConfigurationManager.getBundle().copy(configuration);
}
} else {
Enumeration<URL> en = clazz.getClassLoader().getResources(folderName);
if (en.hasMoreElements()) {
URL url = en.nextElement();
JarURLConnection urlcon = (JarURLConnection) (url.openConnection());
try (JarFile jar = urlcon.getJarFile();) {
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (entry.getName().startsWith(folderName) && !entry.isDirectory()) {
InputStream inputStream = jar.getInputStream(entry);
AbstractConfiguration.setDefaultListDelimiter(';');
PropertiesConfiguration configuration = new PropertiesConfiguration();
configuration.load(inputStream);
ConfigurationManager.getBundle().copy(configuration);
}
}
}
}
}
} catch (IOException | ConfigurationException e) {
e.printStackTrace();
}
}
--
Thanks,
Amit Bhoraniya
You received this message because you are subscribed to the Google Groups "qaf users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qaf-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qaf-users/8ff71f8f-8eba-4eee-889a-593fbc62c0dao%40googlegroups.com.
I missed to change some code. Refer updated one.
To unsubscribe from this group and stop receiving emails from it, send an email to qaf-...@googlegroups.com.