Changeset 23 for src/main/java/geniusweb/partiesserver
- Timestamp:
- 10/08/20 16:02:48 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/geniusweb/partiesserver/jarClassLoader1.java
r1 r23 4 4 import java.io.IOException; 5 5 import java.net.JarURLConnection; 6 import java.net.MalformedURLException; 7 import java.net.URISyntaxException; 6 8 import java.net.URL; 7 9 import java.net.URLClassLoader; … … 10 12 /** 11 13 * Classloader that ensures loaded code is kept separate from other loaded code. 12 * This is to prevent dependency conflicts between parties that we 14 * This is to prevent dependency conflicts between parties that we load. 13 15 * 14 16 */ … … 17 19 private URL u; 18 20 21 /** 22 * @param url The URL is like 23 * jar:file:/Web%20Servers/../partiesserver-1.4.1/partiesrepo/agentgg-1.5.5.jar!/ 24 * 25 * @param parent the parent classloader. 26 */ 19 27 public JarClassLoader1(URL url, ClassLoader parent) { 20 28 super(new URL[] { url }, parent); 21 29 this.u = url; 22 30 23 String filename = url.getPath(); 24 if (filename.startsWith("file:")) { 25 filename = filename.substring(5); 31 // we need to get to the actual file. This is very tricky, 32 // most solutions on the web don't work, throw, don't remove %20,etc 33 // url.toURI throws for multi-protocol URLs like "jar:file://...". 34 35 // https://docs.oracle.com/javase/7/docs/api/java/net/JarURLConnection.html 36 // the syntax of a JAR URL is: jar:<url>!/{entry} 37 38 String filename = url.getPath(); // file:/bla%20bla/file.jar!/ 39 filename = filename.substring(0, filename.indexOf("!/")); 40 File jarfile; 41 try { 42 jarfile = new File(new URL(filename).toURI()); 43 } catch (MalformedURLException | URISyntaxException e) { 44 throw new IllegalArgumentException( 45 "file " + filename + " seems malformed", e); 26 46 } 27 if (filename.endsWith("/")) {28 filename = filename.substring(0, filename.length() - 1);29 }30 if (filename.endsWith("!")) {31 filename = filename.substring(0, filename.length() - 1);32 }33 34 File jarfile = new File(filename);35 47 36 48 if (jarfile == null || !jarfile.exists()) {
Note:
See TracChangeset
for help on using the changeset viewer.