Continuation of the question . Learned and figured out how XJC generates classes for types. Hence the question - how to dynamically connect and use them?

  • Interesting, I did not understand the question? - Gorets
  • @Gorets, what exactly is not clear? If necessary, I can describe in more detail. - stck
  • Question about code generation at run-time? - Nofate
  • @Nofate, a question about the use and connection of classes that are externalized by an external program during operation - stck
  • @stck,> externalized by external program Do you want to connect a class created in another to one application? - teanYCH

1 answer 1

I understood the question. The question is complicated. Essentially, it is about compiling source codes and linking to app in runtime - it actually consists of 2 parts:

  1. How to connect a class in runtime
  2. How to compile a class in runtime

If the first is solved by the class loader — a construct of type Class.forName() in conjunction with ClassLoader , then the second question is more complicated, but using Java> = 6 this can be solved:

 String fileToCompile = "MyClass.java"; JavaCompiler compiler = javax.tools.ToolProvider.getSystemJavaCompiler(); int compilationResult = compiler.run(null, null, null, fileToCompile); 

If Java <6 then there are only undocumented features (I already forgot what).

  • @Barmaley, thanks. The second day you help me out. Only one single question - after we use the source code compiler (JavaCompilier) will there be extra files? Or directions? Or something of this kind. - stck
  • @stck yes xs ... manage the compiler keys and push the output to a thread directory, and tell the compiler that the temporary directory is there. In theory, all the garbage after the compiler will remain in the temporary directory, and your classes will fall into another directory - Barmaley