Question

I have a requirement in which my front-end screen creates an XSD at run time.

After which i need to create Java Classes for the same then zip it into an war file. all this needs to be done at run time and within JVM.

I have researched on this and found that xjc( xjc -p foo myschema.xsd ) tool command. Unfortunately it seems that the tool cannot be run from inside my java application.

There is an Process API to run the tool from Java, but i think it will make it OS dependent.

Please help me.

I need to generated Java Source Code or direct Binaries(Class Files) from XSD at run time and package the same to an EAR.

Was it helpful?

Solution

You can definitely run the tool from your Java program, just like any other application can be invoked that way.

You can even supply the current working directory when executing the Process.

As long as you don't do anything OS dependent, then you won't make your application OS dependent. This is particularly relevant when supplying the paths. If they are relative, then use Linux style paths (and avoid spaces in the paths) to stay safe.

Once you do that, you can group the *.java and *.class files and Jar them using regular Java tools. From there, you can use some API to load the EAR into your Java EE environment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top