Skip to content

Commit

Permalink
Derive JAR path from ProtectionDomain in order to work when SchemaSpy…
Browse files Browse the repository at this point in the history
… is called from external frameworks for multiple schemas
  • Loading branch information
sturton committed May 20, 2012
1 parent 65db5d6 commit a933cb7
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/main/java/net/sourceforge/schemaspy/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLDecoder;
import java.sql.DatabaseMetaData;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -1210,7 +1211,25 @@ public boolean isDbHelpRequired() {

public static String getLoadedFromJar() {
String classpath = System.getProperty("java.class.path");
return new StringTokenizer(classpath, File.pathSeparator).nextToken();
String loadedFrom = new StringTokenizer(classpath, File.pathSeparator).nextToken();
String path = Config.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = null ;
try {
decodedPath = URLDecoder.decode(path, "UTF-8");
}
catch (java.io.UnsupportedEncodingException uee) {
System.err.println("Unsupported UTF-8 encoding exception caught processing path = \""
+ "\" - defaulting to first classpath element"
);
decodedPath = loadedFrom ;
}
System.err.println("classpath="+classpath);
System.err.println("loadedFrom="+loadedFrom);
System.err.println("path="+path);
System.err.println("decodedPath="+decodedPath);
return decodedPath ;
//return loadedFrom ;
//return new StringTokenizer(classpath, File.pathSeparator).nextToken();
}

/**
Expand Down Expand Up @@ -1718,4 +1737,4 @@ public List<String> asList() throws IOException {

return params;
}
}
}

0 comments on commit a933cb7

Please sign in to comment.