Ignore:
Timestamp:
Mar 6, 2012 2:04:04 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
175e464c
Parents:
de2b204
Message:
  • Webapp class loader: Fix dup classes in classpath caused by last checkin (symptom: i2psnark in wrong directory)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/WebAppConfiguration.java

    rde2b204 r0cea3e0  
    22
    33import java.io.File;
     4import java.net.URL;
     5import java.net.URLClassLoader;
     6import java.util.HashSet;
    47import java.util.Properties;
     8import java.util.Set;
    59import java.util.StringTokenizer;
    610
     
    8488        StringTokenizer tok = new StringTokenizer(cp, " ,");
    8589        StringBuilder buf = new StringBuilder();
     90        Set<URL> systemCP = getSystemClassPath();
    8691        while (tok.hasMoreTokens()) {
    8792            if (buf.length() > 0)
     
    95100            else
    96101                path = dir.getAbsolutePath() + '/' + elem;
     102            // As of Jetty 6, we can't add dups to the class path, or
     103            // else it screws up statics
     104            File jfile = new File(path);
     105            File jdir = jfile.getParentFile();
     106            if (systemCP.contains(jfile.toURI().toURL()) ||
     107                (jdir != null && systemCP.contains(jdir.toURI().toURL()))) {
     108                //System.err.println("Not adding " + path + " to classpath for " + appName + ", already in system classpath");
     109                continue;
     110            }
    97111            System.err.println("Adding " + path + " to classpath for " + appName);
    98112            buf.append(path);
    99113        }
     114        if (buf.length() <= 0)
     115            return;
    100116        ClassLoader cl = _wac.getClassLoader();
    101117        if (cl != null && cl instanceof WebAppClassLoader) {
     
    108124            _wac.setExtraClasspath(buf.toString());
    109125        }
     126    }
     127
     128    /** @since 0.9 */
     129    private static Set<URL> getSystemClassPath() {
     130        URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
     131        URL urls[] = urlClassLoader.getURLs();
     132        Set<URL> rv = new HashSet(32);
     133        for (int i = 0; i < urls.length; i++) {
     134            rv.add(urls[i]);
     135        }
     136        return rv;
    110137    }
    111138
Note: See TracChangeset for help on using the changeset viewer.