Assuming /files/testdir is an existing directory with a few files in it, type at the commandline on Solaris using the JDK1.2Beta3...
jar cf0 classes.jar /files/testdir
You should see the following exception...
java.io.FileNotFoundException: files/testdir/<name of a file in the directory>
at java.io.FileInputStream.<init>(FileInputStream.java:58)
at sun.tools.jar.Manifest.doHashes(Manifest.java:175)
at sun.tools.jar.Manifest.addFile(Manifest.java:159)
at sun.tools.jar.Manifest.addFiles(Manifest.java:131)
at sun.tools.jar.Manifest.addFiles(Manifest.java:129)
at sun.tools.jar.Main.create(Main.java:255)
at sun.tools.jar.Main.run(Main.java:97)
at sun.tools.jar.Main.main(Main.java:524)
This behavior is only seen when not specifying the M flag. When you don't specify the M flag, a sequence of methods get called, one of which is localToStd(String name) located in sun.tools.jar.Manifest.java. This method appeared as follows in 1.1.6...
private final String localToStd(String name) {
return name.replace(java.io.File.separatorChar, '/');
}
but in 1.2 appears as...
private final String localToStd(String name) {
name = name.replace(java.io.File.separatorChar, '/');
if (name.startsWith("./"))
name = name.substring(2);
else if (name.startsWith("/"))
name = name.substring(1);
return name;
}
The fact that I pass a path beginning with a '/' causes this method to remove it which results in an invalid path and thus, a filenotfound exception. My current application relies on the beginning forward slash not being removed.
jar cf0 classes.jar /files/testdir
You should see the following exception...
java.io.FileNotFoundException: files/testdir/<name of a file in the directory>
at java.io.FileInputStream.<init>(FileInputStream.java:58)
at sun.tools.jar.Manifest.doHashes(Manifest.java:175)
at sun.tools.jar.Manifest.addFile(Manifest.java:159)
at sun.tools.jar.Manifest.addFiles(Manifest.java:131)
at sun.tools.jar.Manifest.addFiles(Manifest.java:129)
at sun.tools.jar.Main.create(Main.java:255)
at sun.tools.jar.Main.run(Main.java:97)
at sun.tools.jar.Main.main(Main.java:524)
This behavior is only seen when not specifying the M flag. When you don't specify the M flag, a sequence of methods get called, one of which is localToStd(String name) located in sun.tools.jar.Manifest.java. This method appeared as follows in 1.1.6...
private final String localToStd(String name) {
return name.replace(java.io.File.separatorChar, '/');
}
but in 1.2 appears as...
private final String localToStd(String name) {
name = name.replace(java.io.File.separatorChar, '/');
if (name.startsWith("./"))
name = name.substring(2);
else if (name.startsWith("/"))
name = name.substring(1);
return name;
}
The fact that I pass a path beginning with a '/' causes this method to remove it which results in an invalid path and thus, a filenotfound exception. My current application relies on the beginning forward slash not being removed.
- relates to
-
JDK-4133394 jar tool extractor must do a File.mkdirs() instead of File.mkdir()
-
- Closed
-