diff --git a/node/src/main/java/CordaCaplet.java b/node/src/main/java/CordaCaplet.java index 129b1e7dee..55b05d86f2 100644 --- a/node/src/main/java/CordaCaplet.java +++ b/node/src/main/java/CordaCaplet.java @@ -12,8 +12,8 @@ import java.util.*; public class CordaCaplet extends Capsule { - private Config nodeConfig = null; - private String baseDir = null; + protected Config nodeConfig = null; + protected String baseDir = null; protected CordaCaplet(Capsule pred) { super(pred); @@ -156,7 +156,7 @@ public class CordaCaplet extends Capsule { } else return super.attribute(attr); } - private void augmentClasspath(List classpath, File dir) { + protected void augmentClasspath(List classpath, File dir) { try { if (dir.exists()) { // The following might return null if the directory is not there (we check this already) or if an I/O error occurs. @@ -179,7 +179,7 @@ public class CordaCaplet extends Capsule { } } - private Boolean checkIfCordappDirExists(File dir) { + protected Boolean checkIfCordappDirExists(File dir) { try { if (!dir.mkdir() && !dir.exists()) { // It is unlikely to enter this if-branch, but just in case. logOnFailedCordappDir(); diff --git a/node/src/main/java/CordaWebServerCaplet.java b/node/src/main/java/CordaWebServerCaplet.java new file mode 100644 index 0000000000..7bb1aa916f --- /dev/null +++ b/node/src/main/java/CordaWebServerCaplet.java @@ -0,0 +1,25 @@ +import java.io.File; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; + +public class CordaWebServerCaplet extends CordaCaplet { + protected CordaWebServerCaplet(Capsule pred) { + super(pred); + } + + @Override + @SuppressWarnings("unchecked") + protected T attribute(Map.Entry attr) { + T cp = super.attribute(attr); + if (ATTR_APP_CLASS_PATH == attr) { + File cordappsDir = new File(baseDir, "cordapps"); + // Create cordapps directory if it doesn't exist. + if (checkIfCordappDirExists(cordappsDir)) { + // Add additional directories of JARs to the classpath (at the end), e.g., for JDBC drivers. + augmentClasspath((List) cp, cordappsDir); + } + } + return cp; + } +} diff --git a/webserver/webcapsule/build.gradle b/webserver/webcapsule/build.gradle index 9d63c537a3..fb60a6ca86 100644 --- a/webserver/webcapsule/build.gradle +++ b/webserver/webcapsule/build.gradle @@ -38,7 +38,9 @@ task buildWebserverJar(type: FatCapsule, dependsOn: project(':node').tasks.jar) applicationSource = files( project(':webserver').configurations.runtimeClasspath, project(':webserver').tasks.jar, + project(':node').sourceSets.main.java.outputDir.toString() + '/CordaWebServerCaplet.class', project(':node').sourceSets.main.java.outputDir.toString() + '/CordaCaplet.class', + project(':node').sourceSets.main.java.outputDir.toString() + '/CordaWebServerCaplet$1.class', project(':node').sourceSets.main.java.outputDir.toString() + '/CordaCaplet$1.class', project(':node').buildDir.toString() + '/resources/main/reference.conf', "$rootDir/config/dev/log4j2.xml", @@ -52,7 +54,7 @@ task buildWebserverJar(type: FatCapsule, dependsOn: project(':node').tasks.jar) systemProperties['visualvm.display.name'] = 'Corda Webserver' minJavaVersion = '1.8.0' minUpdateVersion['1.8'] = java8_minUpdateVersion - caplets = ['CordaCaplet'] + caplets = ['CordaWebServerCaplet'] // JVM configuration: // - Constrain to small heap sizes to ease development on low end devices.