本文整理汇总了Java中java.util.jar.Attributes.containsKey方法的典型用法代码示例。如果您正苦于以下问题:Java Attributes.containsKey方法的具体用法?Java Attributes.containsKey怎么用?Java Attributes.containsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.Attributes
的用法示例。
在下文中一共展示了Attributes.containsKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transform
import java.util.jar.Attributes; //导入方法依赖的package包/类
InputStream transform(InputStream inputStream) throws MojoExecutionException {
try (InputStream in = inputStream) { // No need for new variable in Java 9.
Manifest manifest = new Manifest(in);
Attributes attributes = manifest.getMainAttributes();
if (!attributes.containsKey(PREMAIN_CLASS)) {
throw new MojoExecutionException(PREMAIN_CLASS + " not found in MANIFEST.MF. This is a bug in promagent-maven-plugin.");
}
attributes.put(CREATED_BY, pluginArtifactId + ":" + pluginVersion);
ByteArrayOutputStream out = new ByteArrayOutputStream();
manifest.write(out);
return new ByteArrayInputStream(out.toByteArray());
} catch (IOException e) {
throw new MojoExecutionException("Failed to transform MANIFEST.MF: " + e.getMessage(), e);
}
}
示例2: getMainClassFromJar
import java.util.jar.Attributes; //导入方法依赖的package包/类
static String getMainClassFromJar(String jarname) {
String mainValue = null;
try (JarFile jarFile = new JarFile(jarname)) {
Manifest manifest = jarFile.getManifest();
if (manifest == null) {
abort(null, "java.launcher.jar.error2", jarname);
}
Attributes mainAttrs = manifest.getMainAttributes();
if (mainAttrs == null) {
abort(null, "java.launcher.jar.error3", jarname);
}
mainValue = mainAttrs.getValue(MAIN_CLASS);
if (mainValue == null) {
abort(null, "java.launcher.jar.error3", jarname);
}
/*
* Hand off to FXHelper if it detects a JavaFX application
* This must be done after ensuring a Main-Class entry
* exists to enforce compliance with the jar specification
*/
if (mainAttrs.containsKey(
new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) {
return FXHelper.class.getName();
}
return mainValue.trim();
} catch (IOException ioe) {
abort(ioe, "java.launcher.jar.error1", jarname);
}
return null;
}
示例3: getMainClassFromJar
import java.util.jar.Attributes; //导入方法依赖的package包/类
static String getMainClassFromJar(String jarname) {
String mainValue;
try (JarFile jarFile = new JarFile(jarname)) {
Manifest manifest = jarFile.getManifest();
if (manifest == null) {
abort(null, "java.launcher.jar.error2", jarname);
}
Attributes mainAttrs = manifest.getMainAttributes();
if (mainAttrs == null) {
abort(null, "java.launcher.jar.error3", jarname);
}
// Main-Class
mainValue = mainAttrs.getValue(MAIN_CLASS);
if (mainValue == null) {
abort(null, "java.launcher.jar.error3", jarname);
}
// Launcher-Agent-Class (only check for this when Main-Class present)
String agentClass = mainAttrs.getValue(LAUNCHER_AGENT_CLASS);
if (agentClass != null) {
ModuleLayer.boot().findModule("java.instrument").ifPresent(m -> {
try {
String cn = "sun.instrument.InstrumentationImpl";
Class<?> clazz = Class.forName(cn, false, null);
Method loadAgent = clazz.getMethod("loadAgent", String.class);
loadAgent.invoke(null, jarname);
} catch (Throwable e) {
if (e instanceof InvocationTargetException) e = e.getCause();
abort(e, "java.launcher.jar.error4", jarname);
}
});
}
// Add-Exports and Add-Opens
String exports = mainAttrs.getValue(ADD_EXPORTS);
if (exports != null) {
addExportsOrOpens(exports, false);
}
String opens = mainAttrs.getValue(ADD_OPENS);
if (opens != null) {
addExportsOrOpens(opens, true);
}
/*
* Hand off to FXHelper if it detects a JavaFX application
* This must be done after ensuring a Main-Class entry
* exists to enforce compliance with the jar specification
*/
if (mainAttrs.containsKey(
new Attributes.Name(JAVAFX_APPLICATION_MARKER))) {
FXHelper.setFXLaunchParameters(jarname, LM_JAR);
return FXHelper.class.getName();
}
return mainValue.trim();
} catch (IOException ioe) {
abort(ioe, "java.launcher.jar.error1", jarname);
}
return null;
}