Make JAR files on classpath a special case for archive

If the user adds a JAR file to the classpath in "spring jar -cp ..."
he expected it to end up in the classpath of the executable jar
(i.e. in the nested lib/ directory). Before this change it would
have gone in the root of the executable JAR, causing errors at runtime.

The fix is slightly awkward, since it assumes that any JAR in the
"roots" of the ResourceMatcher come from the classpath (which *is*
the case currently, but might not always be at least in principle).
Seems like a reasonable compromise given it's a quick change
and some tests have been included.

Fixes gh-565
This commit is contained in:
Dave Syer
2014-03-25 11:36:24 +00:00
parent a821092bbd
commit 60fe468af9
3 changed files with 59 additions and 3 deletions

View File

@@ -155,9 +155,11 @@ public class JarCommand extends OptionParsingCommand {
options.valuesOf(this.excludeOption));
List<File> roots = new ArrayList<File>();
for (URL classpathEntry : classpath) {
roots.add(new File(URI.create(classpathEntry.toString())));
File file = new File(URI.create(classpathEntry.toString()));
roots.add(file);
}
return matcher.find(roots);
List<MatchedResource> found = matcher.find(roots);
return found;
}
private void writeJar(File file, Class<?>[] compiledClasses,

View File

@@ -147,7 +147,7 @@ class ResourceMatcher {
private MatchedResource(File file) {
this.name = file.getName();
this.file = file;
this.root = false;
this.root = this.name.endsWith(".jar");
}
private MatchedResource(File rootFolder, File file) {