下面列出了java.util.jar.JarFile#runtimeVersion ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static JarFile newJarFile(Path path) {
try {
return new JarFile(new File(path.toString()),
true, // verify
ZipFile.OPEN_READ,
JarFile.runtimeVersion());
} catch (IOException ioe) {
throw new UncheckedIOException(ioe);
}
}
static JarFile newJarFile(Path path) {
try {
return new JarFile(new File(path.toString()),
true, // verify
ZipFile.OPEN_READ,
JarFile.runtimeVersion());
} catch (IOException ioe) {
throw new UncheckedIOException(ioe);
}
}
@DataProvider(name = "versions")
public Object[][] createVersionData() throws Exception {
return new Object[][]{
{JarFile.baseVersion(), 8},
{JarFile.runtimeVersion(), Runtime.version().major()},
{Runtime.version(), Runtime.version().major()},
{Runtime.Version.parse("7.1"), JarFile.baseVersion().major()},
{Runtime.Version.parse("9"), 9},
{Runtime.Version.parse("9.1.5-ea+200"), 9}
};
}
@DataProvider
public Object[][] data() {
return new Object[][] {
{Runtime.Version.parse("8")},
{Runtime.Version.parse("9")},
{Runtime.Version.parse("10")},
{Runtime.Version.parse("11")},
{JarFile.baseVersion()},
{JarFile.runtimeVersion()}
};
}
protected void checkMultiRelease(String jarFile,
boolean expected) throws IOException {
try (JarFile jf = new JarFile(new File(jarFile), true,
ZipFile.OPEN_READ, JarFile.runtimeVersion())) {
assertEquals(jf.isMultiRelease(), expected);
}
}
@Test
public void testCustomManifest() throws Throwable {
String jarfile = "test.jar";
compile("test01");
Path classes = Paths.get("classes");
Path manifest = Paths.get("Manifest.txt");
// create
Files.write(manifest, "Class-Path: MyUtils.jar\n".getBytes());
jar("cfm", jarfile, manifest.toString(),
"-C", classes.resolve("base").toString(), ".",
"--release", "10", "-C", classes.resolve("v10").toString(), ".")
.shouldHaveExitValue(SUCCESS)
.shouldBeEmpty();
try (JarFile jf = new JarFile(new File(jarfile), true,
ZipFile.OPEN_READ, JarFile.runtimeVersion())) {
assertTrue(jf.isMultiRelease(), "Not multi-release jar");
assertEquals(jf.getManifest()
.getMainAttributes()
.getValue("Class-Path"),
"MyUtils.jar");
}
// update
Files.write(manifest, "Multi-release: false\n".getBytes());
jar("ufm", jarfile, manifest.toString(),
"-C", classes.resolve("base").toString(), ".",
"--release", "9", "-C", classes.resolve("v10").toString(), ".")
.shouldHaveExitValue(SUCCESS)
.shouldContain("WARNING: Duplicate name in Manifest: Multi-release.");
try (JarFile jf = new JarFile(new File(jarfile), true,
ZipFile.OPEN_READ, JarFile.runtimeVersion())) {
assertTrue(jf.isMultiRelease(), "Not multi-release jar");
assertEquals(jf.getManifest()
.getMainAttributes()
.getValue("Class-Path"),
"MyUtils.jar");
}
FileUtils.deleteFileIfExistsWithRetry(Paths.get(jarfile));
FileUtils.deleteFileTreeWithRetry(Paths.get(usr, "classes"));
}
/**
* Returns a ModuleFinder that locates modules on the file system by
* searching a sequence of directories and/or packaged modules. The modules
* may be patched by the given ModulePatcher.
*/
public static ModuleFinder of(ModulePatcher patcher, Path... entries) {
return new ModulePath(JarFile.runtimeVersion(), false, patcher, entries);
}
/**
* Returns a ModuleFinder that that locates modules on the file system by
* searching a sequence of directories and/or packaged modules. The modules
* may be patched by the given ModulePatcher.
*/
public static ModuleFinder of(ModulePatcher patcher, Path... entries) {
return new ModulePath(JarFile.runtimeVersion(), false, patcher, entries);
}