Generating java bytecode using JCodeModel
You may want to consider one of several java byte code generators: Guide to Java Byte Code Generation?
But if you prefer to work with the JCodeModel lib, you have the option to keep the intermediate Java code in memory as temporary. Here is the sequence of prompts:
(1) Here is an example of how to get the java source in memory: Compile the dynamically generated class at runtime without writing to a file
(2) Then you can use a similar thing to keep the compiled bytecode in memory again: https://github.com/trung/InMemoryJavaCompiler/blob/master/src/main/java/org/mdkt/compiler/InMemoryJavaCompiler. java
(3) Finally, to create a jar file from bytecode stored in memory, just do the following thing: How to use JarOutputStream to create a JAR file?
PS: The last step can be done as a streaming write directly to the database (BLOB field or so).
source to share