String classFileName = classFile.getName();
className = classFileName.substring(0,
classFileName.length() - CLASS_FILENAME_SUFFIX.length());
// Create an empty class.
ClassGen cg = new ClassGen(className, "java.lang.Object",
"<generated>", ACC_PUBLIC, null);
cg.addEmptyConstructor(ACC_PUBLIC);
// Create a class file from the empty class.
try {
cg.getJavaClass().dump(classFile);
} catch (IOException e) {
System.err.println(e.getMessage());
System.exit(1);
}
// Create a JAR containing the empty class.
JarOutputStream jar;
try {
jarFile = File.createTempFile(FILENAME_PREFIX, JAR_FILENAME_SUFFIX);
jarFile.deleteOnExit();
String jarFileName = jarFile.getName();
jarClassName = jarFileName.substring(0,
jarFileName.length() - JAR_FILENAME_SUFFIX.length());
cg = new ClassGen(jarClassName, "java.lang.Object",
"<generated>", ACC_PUBLIC, null);
cg.addEmptyConstructor(ACC_PUBLIC);
jar = new JarOutputStream(new FileOutputStream(jarFile));
JarEntry entry = new JarEntry(jarClassName + ".class");
jar.putNextEntry(entry);
jar.write(cg.getJavaClass().getBytes());
jar.close();
} catch (IOException e) {
System.err.println(e.getMessage());
System.exit(1);
}