From 765c1147fd204fb6bd702e85837ddf7ffef474ae Mon Sep 17 00:00:00 2001 From: kohsuke Date: Thu, 16 Aug 2007 06:07:22 +0000 Subject: [PATCH] when launched through JNLP, the jar location detection fails. (#539) git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@4315 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/maven/MavenBuild.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/java/hudson/maven/MavenBuild.java b/core/src/main/java/hudson/maven/MavenBuild.java index 64f55141d9..eab7ac8930 100644 --- a/core/src/main/java/hudson/maven/MavenBuild.java +++ b/core/src/main/java/hudson/maven/MavenBuild.java @@ -39,6 +39,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.net.URL; +import java.net.JarURLConnection; +import java.net.URLConnection; /** * {@link Run} for {@link MavenModule}. @@ -239,6 +242,17 @@ public class MavenBuild extends AbstractBuild { private static final class GetRemotingJar implements Callable { public String call() throws IOException { + URL classFile = Main.class.getClassLoader().getResource(Launcher.class.getName().replace('.','/')+".class"); + + // 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. + URLConnection con = classFile.openConnection(); + if (con instanceof JarURLConnection) { + JarURLConnection connection = (JarURLConnection) con; + return connection.getJarFile().getName(); + } + return Which.jarFile(Launcher.class).getPath(); } }