Patch for bootclasspath loading

This commit is contained in:
Ander Ruiz
2017-06-13 09:10:39 +02:00
parent 091108a369
commit 0075a7e1ce
10 changed files with 39 additions and 17 deletions

View File

@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
import org.apache.commons.lang3.SystemUtils;
@@ -148,4 +149,13 @@ public final class FileUtils {
}
}
}
/**
* Gets the {@link InputStream} for this resource
* @param resource path
* @return
*/
public static InputStream getResourceAsStream(String resource) {
return FileUtils.class.getClassLoader()!=null?FileUtils.class.getClassLoader().getResourceAsStream(resource):ClassLoader.getSystemResourceAsStream(resource);
}
}

View File

@@ -29,6 +29,7 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.security.ProtectionDomain;
import java.util.Enumeration;
import java.util.Properties;
@@ -440,7 +441,7 @@ public final class Settings {
*/
private Settings(String propertiesFilePath) {
props = new Properties();
try (InputStream in = this.getClass().getClassLoader().getResourceAsStream(propertiesFilePath)) {
try (InputStream in = FileUtils.getResourceAsStream(propertiesFilePath)) {
props.load(in);
} catch (NullPointerException ex) {
LOGGER.error("Did not find settings file '{}'.", propertiesFilePath);
@@ -733,8 +734,12 @@ public final class Settings {
* @return a File object
*/
private static File getJarPath() {
final String jarPath = Settings.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = ".";
String jarPath = "";
ProtectionDomain domain = Settings.class.getProtectionDomain();
if(domain!=null&& domain.getCodeSource()!=null && domain.getCodeSource().getLocation()!=null) {
jarPath = Settings.class.getProtectionDomain().getCodeSource().getLocation().getPath();
}
try {
decodedPath = URLDecoder.decode(jarPath, "UTF-8");
} catch (UnsupportedEncodingException ex) {