From 76c0f56be8a8d68e7d7714d4e494cf5ae13a390c Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Mon, 5 Mar 2012 00:41:36 +0000 Subject: [PATCH] * Plugins: Fix setting webapp classpath on Jetty 6 --- .../i2p/router/web/WebAppConfiguration.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/WebAppConfiguration.java b/apps/routerconsole/java/src/net/i2p/router/web/WebAppConfiguration.java index 249ae4582e..ac84d937a1 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/WebAppConfiguration.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/WebAppConfiguration.java @@ -7,6 +7,7 @@ import java.util.StringTokenizer; import net.i2p.I2PAppContext; import org.mortbay.jetty.webapp.Configuration; +import org.mortbay.jetty.webapp.WebAppClassLoader; import org.mortbay.jetty.webapp.WebAppContext; @@ -45,7 +46,10 @@ public class WebAppConfiguration implements Configuration { return _wac; } - public void configureClassPath() throws Exception { + /** + * This was the interface in Jetty 5, now it's configureClassLoader() + */ + private void configureClassPath() throws Exception { String ctxPath = _wac.getContextPath(); //System.err.println("Configure Class Path " + ctxPath); if (ctxPath.equals("/")) @@ -78,7 +82,10 @@ public class WebAppConfiguration implements Configuration { if (cp == null) return; StringTokenizer tok = new StringTokenizer(cp, " ,"); + StringBuilder buf = new StringBuilder(); while (tok.hasMoreTokens()) { + if (buf.length() > 0) + buf.append(','); String elem = tok.nextToken().trim(); String path; if (elem.startsWith("$I2P")) @@ -88,7 +95,17 @@ public class WebAppConfiguration implements Configuration { else path = dir.getAbsolutePath() + '/' + elem; System.err.println("Adding " + path + " to classpath for " + appName); - _wac.setExtraClasspath(path); + buf.append(path); + } + ClassLoader cl = _wac.getClassLoader(); + if (cl != null && cl instanceof WebAppClassLoader) { + WebAppClassLoader wacl = (WebAppClassLoader) cl; + wacl.addClassPath(buf.toString()); + } else { + // This was not working because the WebAppClassLoader already exists + // and it calls getExtraClasspath in its constructor + // Not sure why WACL already exists... + _wac.setExtraClasspath(buf.toString()); } } @@ -99,5 +116,7 @@ public class WebAppConfiguration implements Configuration { public void deconfigureWebApp() {} /** @since Jetty 6 */ - public void configureClassLoader() {} + public void configureClassLoader() throws Exception { + configureClassPath(); + } } -- GitLab