下面列出了java.util.jar.Manifest#clear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
Manifest createMainClass(File javaFile) throws IOException {
javaFile.delete();
List<String> content = new ArrayList<>();
content.add("public class " + baseName(javaFile) + "{");
content.add("public static void main(String... args) {");
content.add("System.out.println(\"Hello World\\n\");");
content.add("System.exit(0);");
content.add("}");
content.add("}");
createFile(javaFile, content);
compile(javaFile.getName());
Manifest manifest = new Manifest();
manifest.clear();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile));
System.out.println(manifest.getMainAttributes().keySet());
System.out.println(manifest.getMainAttributes().values());
return manifest;
}
private void createJarFromClassPathResources(final FileOutputStream fos,
final String location) throws IOException {
final Manifest m = new Manifest();
m.clear();
final Attributes global = m.getMainAttributes();
if (global.getValue(Attributes.Name.MANIFEST_VERSION) == null) {
global.put(Attributes.Name.MANIFEST_VERSION, "1.0");
}
final File mylocation = new File(location);
global.putValue(BOOT_CLASSPATH, getBootClassPath(mylocation));
global.putValue(PREMAIN_CLASS, AGENT_CLASS_NAME);
global.putValue(AGENT_CLASS, AGENT_CLASS_NAME);
global.putValue(CAN_REDEFINE_CLASSES, "true");
global.putValue(CAN_RETRANSFORM_CLASSES, "true");
global.putValue(CAN_SET_NATIVE_METHOD, "true");
try(JarOutputStream jos = new JarOutputStream(fos, m)) {
addClass(Agent.class, jos);
addClass(CodeCoverageStore.class, jos);
addClass(InvokeReceiver.class, jos);
}
}
private void createJarFromClassPathResources(final FileOutputStream fos,
final String location) throws IOException {
final Manifest m = new Manifest();
m.clear();
final Attributes global = m.getMainAttributes();
if (global.getValue(Attributes.Name.MANIFEST_VERSION) == null) {
global.put(Attributes.Name.MANIFEST_VERSION, "1.0");
}
final File mylocation = new File(location);
global.putValue(BOOT_CLASSPATH, getBootClassPath(mylocation));
global.putValue(PREMAIN_CLASS, AGENT_CLASS_NAME);
global.putValue(CAN_REDEFINE_CLASSES, "true");
global.putValue(CAN_SET_NATIVE_METHOD, "true");
try (JarOutputStream jos = new JarOutputStream(fos, m)) {
addClass(HotSwapAgent.class, jos);
addClass(CodeCoverageStore.class, jos);
addClass(InvokeReceiver.class, jos);
}
}