ADDITIONAL SYSTEM INFORMATION :
I'm using Java 17, but the issue is probably way older - I've tested with Java 11 and it is also there.
A DESCRIPTION OF THE PROBLEM :
UNC paths with regular url are not working when used in a jar manifest:
Manifest-Version: 1.0
Class-Path: file://server/path/
Main-Class: com.main.Start
But this irregular syntax does work:
Manifest-Version: 1.0
Class-Path: file:////server/path/
Main-Class: com.main.Start
Background: Maven surefire plugin creates a temporary jar for forked test execution and adds all the classpath entries to the manifest. At some point the implementation changed from File to Path. But the Java implementation of File.toURI() and Path.toUri() behaves differently for UNC paths (File produces file://// which was working in the jar manifest, but Path produces file:// which won't work). See also https://issues.apache.org/jira/browse/SUREFIRE-2211
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
* Create some class with a main method at an unc path like //server/path/com/main/Start.class.
* Create a jar with such a manifest
Manifest-Version: 1.0
Class-Path: file://server/path/
Main-Class: com.main.Start
* execute the jar via
java -jar test.jar
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Class gets executed
ACTUAL -
java.lang.ClassNotFoundException: de.main.Start
CUSTOMER SUBMITTED WORKAROUND :
stay with the old File.toURI() for absolute UNC paths
I'm using Java 17, but the issue is probably way older - I've tested with Java 11 and it is also there.
A DESCRIPTION OF THE PROBLEM :
UNC paths with regular url are not working when used in a jar manifest:
Manifest-Version: 1.0
Class-Path: file://server/path/
Main-Class: com.main.Start
But this irregular syntax does work:
Manifest-Version: 1.0
Class-Path: file:////server/path/
Main-Class: com.main.Start
Background: Maven surefire plugin creates a temporary jar for forked test execution and adds all the classpath entries to the manifest. At some point the implementation changed from File to Path. But the Java implementation of File.toURI() and Path.toUri() behaves differently for UNC paths (File produces file://// which was working in the jar manifest, but Path produces file:// which won't work). See also https://issues.apache.org/jira/browse/SUREFIRE-2211
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
* Create some class with a main method at an unc path like //server/path/com/main/Start.class.
* Create a jar with such a manifest
Manifest-Version: 1.0
Class-Path: file://server/path/
Main-Class: com.main.Start
* execute the jar via
java -jar test.jar
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Class gets executed
ACTUAL -
java.lang.ClassNotFoundException: de.main.Start
CUSTOMER SUBMITTED WORKAROUND :
stay with the old File.toURI() for absolute UNC paths