简体   繁体   English

在运行时从XSD创建Java类

[英]Create Java Class from XSD at run time

I have a requirement in which my front-end screen creates an XSD at run time. 我有一个要求,要求我的前端屏幕在运行时创建XSD。

After which i need to create Java Classes for the same then zip it into an war file. 之后,我需要为它创建Java类,然后将其压缩到war文件中。 all this needs to be done at run time and within JVM. 所有这些都需要在运行时以及在JVM中完成。

I have researched on this and found that xjc ( xjc -p foo myschema.xsd ) tool command. 我对此进行了研究,发现了xjcxjc -p foo myschema.xsd )工具命令。 Unfortunately it seems that the tool cannot be run from inside my java application. 不幸的是,该工具似乎无法从我的Java应用程序内部运行。

There is an Process API to run the tool from Java, but i think it will make it OS dependent. 有一个Process API可以从Java运行该工具,但是我认为它将使它依赖于OS。

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. 我需要在运行时从XSD生成Java源代码或直接将Binaries(Class Files)打包到EAR。

You can definitely run the tool from your Java program, just like any other application can be invoked that way. 您绝对可以从Java程序中运行该工具,就像可以以这种方式调用任何其他应用程序一样。

You can even supply the current working directory when exec uting the Process . exec 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. 如果它们是相对的,请使用Linux样式路径(并避免在路径中留空格)以确保安全。

Once you do that, you can group the *.java and *.class files and Jar them using regular Java tools. 完成此操作后,您可以将*.java*.class文件分组并使用常规Java工具对它们进行Jar。 From there, you can use some API to load the EAR into your Java EE environment. 从那里,您可以使用一些API将EAR加载到Java EE环境中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM