Maybe someone can help me.
How can I generate a jar library similar to android.jar located in android sdk-platform.
It should remove all methods implementations and replace it with throw new RuntimeException("Stub!");
like this:
AppWidgetManager() { throw new RuntimeException("Stub!"); }
public NdefMessage(NdefRecord[] records) { throw new RuntimeException("Stub!"); }
public NdefRecord[] getRecords() { throw new RuntimeException("Stub!"); }
All public members are also present.
In general, to include all of the JARs in a given directory, you can use the wildcard * (not *. jar ). The wildcard only matches JARs, not class files; to get all classes in a directory, just end the classpath entry at the directory name.
A JAR serves the same function an an Assembly in the C#/. net world. It's a collection of java classes, a manifest, and optionally other resources, such as properties files. A library is a more abstract concept, in java, a library is usually packaged as a JAR (Java ARchive), or a collection of JARs.
If no one else gives a solution, it is a very simple case.
Simplest might be to use java's reflection, reading all classes from a jar and generate java source code.
Amd then there are libraries like ASM; byte code manipulation and also java dom source generation libraries.
A simple solution with javassist (I did not test, but roughly, this should be it):
ClassPool pool = new ClassPool();
pool.appendClassPath("pathToYourJar");
CtClass clazz = pool.get("Your class");
CtMethod throwingMethod = CtMethod.make("throw new RuntimeException();",clazz);
for(CtMethod method : clazz.getDeclaredMethods()){
method.setBody(throwingMethod,null);
}
clazz.writeFile("pathToYourNewClassDirectory");
//zip the classes in your new class directory into a jar,
// add a manifest if you need to, deploy to where you want it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With