Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8320760

Jar manifest Class-Path attribute does not work with regular UNC paths

XMLWordPrintable

    • jar
    • generic
    • windows

      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

            lancea Lance Andersen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: