提交 d3ce09f6 编写于 作者: K kohsuke

fixed a problem when hudson.war is loaded from remote java.net site


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@2546 71c3de6d-444a-0410-be80-ed276b4c234a
上级 829a69e1
......@@ -7,6 +7,7 @@ import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.JarURLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......@@ -54,17 +55,11 @@ public class Main {
*/
public static File whoAmI() throws IOException, URISyntaxException {
URL classFile = Main.class.getClassLoader().getResource("Main.class");
String loc = classFile.toExternalForm().substring(4);// cut off jar:
loc = loc.substring(0,loc.lastIndexOf('!'));
// JNLP launcher's classloader incorrectly returns file:c:/foobar/...
if(loc.startsWith("file:") && !loc.startsWith("file:/")) {
loc = "file:/"+loc.substring(5);
}
// assume 'loc' is a file URL and return the file name.
// toURI needed to handle %20 in URL.
return new File(new URL(loc).toURI().getPath());
// JNLP returns the URL where the jar was originally placed (like http://hudson.dev.java.net/...)
// not the local cached file. So we need a rather round about approach to get to
// the local file name.
return new File(((JarURLConnection)classFile.openConnection()).getJarFile().getName());
}
private static void copyStream(InputStream in, OutputStream out) throws IOException {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册