I am writing a program that creates and generates JavaFileObjects from JAXB. Currently I have made it so my .java files are made using JAXB, then loaded into an array. I want to take the JavaFileObjects and pass them into JAXB and have JAXB compile and classload them for use in further processing.
The code that currently generates the .java files are:
String outputDirectory = jaxbPackageGenFolderCreation();
// Setup schema compiler
SchemaCompiler sc = XJC.createSchemaCompiler();
sc.forcePackageName(getPackageName());
LOG.info("PackageName: " + getPackageName());
LOG.info("creating BINDINGS_XJB: " + MageekConstants.BINDINGS_XJB);
File bindings = new File(MageekConstants.BINDINGS_XJB);
/*
* sc.getOptions.addBindFile adds the xjc bindings file to the the schema compiler.
* This method shows deprecated, however it is not being removed from future
* versions of the API. It is not being maintained in future versions so the
* developers have it annotated as depreciated as a notification tool. Future
* stability of this call is NOT guaranteed.
*/
sc.getOptions().addBindFile(bindings);
// Setup SAX InputSource
LOG.info("schema file: " + getXsdFile());
File schemaFile = new File(getXsdFile());
InputSource is = new InputSource(schemaFile.toURI().toString());
// Parse & build
sc.parseSchema(is);
S2JJAXBModel model = sc.bind();
JCodeModel jCodeModel = model.generateCode(null, null);
String[] splitArray = null;
try
{
PrintStream printStream = new PrintStream(new File(MageekConstants.TEMP_DIR
+ "GeneratedFiles.mageek"));
jCodeModel.build(new File(outputDirectory), printStream);
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// CodeWriter codeWriter = new SingleStreamCodeWriter(baos);
// jCodeModel.build(codeWriter);
I have looked into in memory java compiling and other methods, but none seem to be doing what I want without any IO's to disk. I was told by a friend that JAXB can take the .java files and then class load them. I have found no documentation on this or examples. Any help would be great.