diff --git a/build.gradle b/build.gradle
index 3ecfc3a2b1..8e72b1aa8d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -204,19 +204,19 @@ sourceSets {
resources {
srcDirs = getDirectoryInActiveComponentsIfExists('src/main/java')
srcDirs += getDirectoryInActiveComponentsIfExists('config')
+ srcDirs += "${rootDir}/framework/base/dtd"
exclude excludedJavaSources
exclude excludedConfigFiles
// Below are necessary for unit tests run by Gradle and integration tests
+ exclude { FileTreeElement elem -> elem.getName().contains('.Labels.xml') }
exclude { FileTreeElement elem -> elem.getName().contains('.properties') &&
!elem.getName().contains('start.properties') &&
!elem.getName().contains('load-data.properties') &&
!elem.getName().contains('debug.properties') &&
!elem.getName().contains('cache.properties') &&
!elem.getName().contains('test.properties') &&
- !elem.getName().contains('rmi.properties')}
- exclude { FileTreeElement elem -> elem.getName().contains('.xml') &&
- !elem.getName().contains('entityengine.xml')
- }
+ !elem.getName().contains('rmi.properties')
+ }
}
}
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java
index 3172dd4c6e..0aa02de4ad 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java
@@ -22,6 +22,8 @@ import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -30,7 +32,6 @@ import org.apache.ofbiz.base.component.ComponentConfig;
import org.apache.ofbiz.base.component.ComponentException;
import org.apache.ofbiz.base.component.ComponentLoaderConfig;
import org.apache.ofbiz.base.start.Classpath;
-import org.apache.ofbiz.base.start.NativeLibClassLoader;
import org.apache.ofbiz.base.start.Start;
import org.apache.ofbiz.base.start.StartupCommand;
import org.apache.ofbiz.base.util.Debug;
@@ -43,7 +44,7 @@ import org.apache.ofbiz.base.util.FileUtil;
* defined in OFBiz. This container must run before any other containers to
* allow components to access any necessary resources. Furthermore, the
* ComponentContainer also builds up the ComponentConfigCache
- * to keep track of all loaded components
+ * defined in ComponentConfig to keep track of loaded components
*
*/
public class ComponentContainer implements Container {
@@ -52,6 +53,7 @@ public class ComponentContainer implements Container {
private String name;
private final AtomicBoolean loaded = new AtomicBoolean(false);
+ private final List componentsClassPath = new ArrayList();
@Override
public void init(List ofbizCommands, String name, String configFile) throws ContainerException {
@@ -68,6 +70,7 @@ public class ComponentContainer implements Container {
} catch (IOException | ComponentException e) {
throw new ContainerException(e);
}
+ loadClassPathForAllComponents(componentsClassPath);
Debug.logInfo("All components loaded", module);
}
@@ -78,6 +81,28 @@ public class ComponentContainer implements Container {
return loaded.get();
}
+ /**
+ * Iterate over all the components and load their classpath URLs into the classloader
+ * and set the classloader as the context classloader
+ *
+ * @param componentsClassPath: a list of classpaths for all components
+ * @throws ContainerException
+ */
+ private void loadClassPathForAllComponents(List componentsClassPath) throws ContainerException {
+ List allComponentUrls = new ArrayList();
+ for(Classpath classPath : componentsClassPath) {
+ try {
+ allComponentUrls.addAll(Arrays.asList(classPath.getUrls()));
+ } catch (MalformedURLException e) {
+ Debug.logError("Unable to load component classpath" + classPath.toString(), module);
+ Debug.logError(e.getMessage(), module);
+ }
+ }
+ URL[] componentURLs = allComponentUrls.toArray(new URL[allComponentUrls.size()]);
+ URLClassLoader classLoader = new URLClassLoader(componentURLs, Thread.currentThread().getContextClassLoader());
+ Thread.currentThread().setContextClassLoader(classLoader);
+ }
+
/**
* Checks if ComponentDef.type is a directory or a single component.
* If it is a directory, load the directory, otherwise load a single component
@@ -197,28 +222,19 @@ public class ComponentContainer implements Container {
/**
* Load a single component by adding all its classpath entries to
- * the classloader
+ * the list of classpaths to be loaded
*
* @param config: the component configuration
* @throws IOException
*/
private void loadComponent(ComponentConfig config) throws IOException {
- if (!config.enabled()) {
+ if (config.enabled()) {
+ Classpath classpath = buildClasspathFromComponentConfig(config);
+ componentsClassPath.add(classpath);
+ Debug.logInfo("Added class path for component : [" + config.getComponentName() + "]", module);
+ } else {
Debug.logInfo("Not loading component [" + config.getComponentName() + "] because it is disabled", module);
- return;
}
-
- NativeLibClassLoader classloader = (NativeLibClassLoader) Thread.currentThread().getContextClassLoader();
- Classpath classPath = buildClasspathFromComponentConfig(config);
-
- for (URL url : classPath.getUrls()) {
- classloader.addURL(url);
- }
- for (File folder : classPath.getNativeFolders()) {
- classloader.addNativeClassPath(folder);
- }
-
- Debug.logInfo("Loaded component : [" + config.getComponentName() + "]", module);
}
/**
diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java
index edf4e7766d..807d45cb1c 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java
@@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import java.util.stream.Collectors;
import org.apache.ofbiz.base.component.ComponentConfig;
@@ -31,7 +30,6 @@ import org.apache.ofbiz.base.start.StartupCommand;
import org.apache.ofbiz.base.start.StartupException;
import org.apache.ofbiz.base.start.StartupLoader;
import org.apache.ofbiz.base.util.Debug;
-import org.apache.ofbiz.base.util.StringUtil;
import org.apache.ofbiz.base.util.UtilValidate;
import edu.emory.mathcs.backport.java.util.Collections;
@@ -57,12 +55,7 @@ public class ContainerLoader implements StartupLoader {
public synchronized void load(Config config, List ofbizCommands) throws StartupException {
// loaders defined in startup (e.g. main, test, load-data, etc ...)
- List loaders = null;
- for (Map loaderMap: config.loaders) {
- if (module.equals(loaderMap.get("class"))) {
- loaders = StringUtil.split((String)loaderMap.get("profiles"), ",");
- }
- }
+ List loaders = config.loaders;
// load containers defined in ofbiz-containers.xml
Debug.logInfo("[Startup] Loading containers...", module);
diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/Classpath.java b/framework/start/src/main/java/org/apache/ofbiz/base/start/Classpath.java
index e2732c7073..fb1618b5dc 100644
--- a/framework/start/src/main/java/org/apache/ofbiz/base/start/Classpath.java
+++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/Classpath.java
@@ -35,9 +35,7 @@ import java.util.List;
*/
public final class Classpath {
- private static final String nativeLibExt = System.mapLibraryName("someLib").replace("someLib", "").toLowerCase();
private List elements = new ArrayList();
- private final List nativeFolders = new ArrayList();
/**
* Default constructor.
@@ -103,7 +101,6 @@ public final class Classpath {
}
if (path.isDirectory() && path.exists()) {
// load all .jar, .zip files and native libs in this directory
- boolean containsNativeLibs = false;
for (File file : path.listFiles()) {
String fileName = file.getName().toLowerCase();
if (fileName.endsWith(".jar") || fileName.endsWith(".zip")) {
@@ -113,16 +110,6 @@ public final class Classpath {
elements.add(key);
}
}
- } else if (fileName.endsWith(nativeLibExt)) {
- containsNativeLibs = true;
- }
- }
- if (containsNativeLibs) {
- File key = path.getCanonicalFile();
- synchronized (nativeFolders) {
- if (!nativeFolders.contains(key)) {
- nativeFolders.add(key);
- }
}
}
} else {
@@ -140,17 +127,6 @@ public final class Classpath {
}
}
- /**
- * Returns a list of folders containing native libraries.
- *
- * @return A list of folders containing native libraries
- */
- public List getNativeFolders() {
- synchronized (nativeFolders) {
- return new ArrayList(nativeFolders);
- }
- }
-
/**
* Returns a list of class path component URLs.
*
diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java b/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java
index df2466dc32..351db30488 100644
--- a/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java
+++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java
@@ -20,14 +20,11 @@ package org.apache.ofbiz.base.start;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -35,6 +32,8 @@ import java.util.Optional;
import java.util.Properties;
import java.util.TimeZone;
+import org.apache.ofbiz.base.util.StringUtil;
+
/**
* OFBiz server parameters needed on system startup and retrieved from
* one of the properties files in the start component
@@ -42,33 +41,25 @@ import java.util.TimeZone;
public final class Config {
public final String ofbizHome;
- public final String awtHeadless;
public final InetAddress adminAddress;
public final String adminKey;
public final int portOffset;
public final int adminPort;
public final String containerConfig;
- public final List