@@ -337,6 +337,21 @@ void javaDashJarFindsClassPathManifestEntries() throws Exception {
337337 assertThat (result .replace ("\\ " , "/" )).contains ("!!!!" ).contains ("/lib/asset.jar!/assets/file.txt" );
338338 }
339339
340+ @ Test
341+ void javaDashJarFindsAbsoluteClassPathManifestEntries () throws Exception {
342+ Path assetJar = this .temp .resolve ("dependency" ).resolve ("asset.jar" );
343+ Files .createDirectories (assetJar .getParent ());
344+ writeAssetJar (assetJar );
345+ writeApplicationJarWithAbsolutePath (this .temp .resolve ("app.jar" ), assetJar );
346+ String java = ProcessHandle .current ().info ().command ().get ();
347+ Process process = new ProcessBuilder (java , "-jar" , "app.jar" )
348+ .directory (this .temp .toFile ())
349+ .start ();
350+ assertThat (process .waitFor ()).isZero ();
351+ String result = StreamUtils .copyToString (process .getInputStream (), StandardCharsets .UTF_8 );
352+ assertThat (result .replace ("\\ " , "/" )).contains ("!!!!" ).contains ("asset.jar!/assets/file.txt" );
353+ }
354+
340355 private void writeAssetJar (Path path ) throws Exception {
341356 try (JarOutputStream jar = new JarOutputStream (new FileOutputStream (path .toFile ()))) {
342357 jar .putNextEntry (new ZipEntry ("assets/" ));
@@ -392,6 +407,35 @@ private void writeApplicationJar(Path path) throws Exception {
392407 assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isTrue ();
393408 }
394409
410+ private void writeApplicationJarWithAbsolutePath (Path path , Path assetJar ) throws Exception {
411+ Manifest manifest = new Manifest ();
412+ Attributes mainAttributes = manifest .getMainAttributes ();
413+ mainAttributes .put (Name .CLASS_PATH , buildSpringClassPath () + assetJar .toAbsolutePath ());
414+ mainAttributes .put (Name .MAIN_CLASS , ClassPathManifestEntriesTestApplication .class .getName ());
415+ mainAttributes .put (Name .MANIFEST_VERSION , "1.0" );
416+ try (JarOutputStream jar = new JarOutputStream (new FileOutputStream (path .toFile ()), manifest )) {
417+ String appClassResource = ClassUtils .convertClassNameToResourcePath (
418+ ClassPathManifestEntriesTestApplication .class .getName ()) + ClassUtils .CLASS_FILE_SUFFIX ;
419+ String folder = "" ;
420+ for (String name : appClassResource .split ("/" )) {
421+ if (!name .endsWith (ClassUtils .CLASS_FILE_SUFFIX )) {
422+ folder += name + "/" ;
423+ jar .putNextEntry (new ZipEntry (folder ));
424+ jar .closeEntry ();
425+ }
426+ else {
427+ jar .putNextEntry (new ZipEntry (folder + name ));
428+ try (InputStream in = getClass ().getResourceAsStream (name )) {
429+ in .transferTo (jar );
430+ }
431+ jar .closeEntry ();
432+ }
433+ }
434+ }
435+ assertThat (new FileSystemResource (path ).exists ()).isTrue ();
436+ assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isTrue ();
437+ }
438+
395439 private String buildSpringClassPath () throws Exception {
396440 return copyClasses (PathMatchingResourcePatternResolver .class , "spring-core" ) +
397441 copyClasses (LogFactory .class , "commons-logging" );
0 commit comments