java 如何从 xsd 创建 jar 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12560962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:22:37  来源:igfitidea点击:

How to create a jar file from xsd

javajarxsd

提问by Shreyos Adikari

How to create a jarfile containing class files generated from a given xsdfile?
Do we need to create all the java files from xsdand then need to compile and create a jar?
Or, other solutions are there.

如何创建jar包含从给定xsd文件生成的类文件的文件
我们是否需要从中创建所有 java 文件xsd,然后需要编译并创建一个jar?
或者,还有其他解决方案。

Can anyone please explain the process?

谁能解释一下这个过程?

采纳答案by Piotr Gwiazda

I guess that you are trying create Java classes from XSD for futher XML<->POJO mapping. Am I right?

我猜您正在尝试从 XSD 创建 Java 类以进行进一步的 XML<->POJO 映射。我对吗?

If so - it depends on mapping lib that you use. Assume that you are using JAXB 2. The easiest way is to use XJC Maven plugin like here : http://mojo.codehaus.org/xjc-maven-plugin/usage.htmland Maven will package everything to JAR then.

如果是这样 - 这取决于您使用的映射库。假设您使用的是 JAXB 2。最简单的方法是使用 XJC Maven 插件,如下所示:http: //mojo.codehaus.org/xjc-maven-plugin/usage.html然后 Maven 会将所有内容打包到 JAR。

回答by Saurav

You can use the following steps if you are not using mavne to generate jar-

如果不使用 mavne 生成 jar,可以使用以下步骤

  1. Copy your xsd to a folder.- eg Test.xsd

  2. From the command prompt go to the folder and use the command-

    xjc Test.xsd

  1. 将您的 xsd 复制到一个文件夹中。- 例如 Test.xsd

  2. 从命令提示符转到文件夹并使用命令 -

    xjc 测试.xsd

or u can use xjc -p --package name--

或者你可以使用 xjc -p --package name--

xjc -p test Test.xsd

xjc -p 测试Test.xsd

This will create all your java files from the xsd, in a folder called generated(default) or test inside your working folder.

这将从 xsd 创建您所有的 java 文件,在您的工作文件夹中名为 generate(default) 或 test 的文件夹中。

  1. From the command prompt use -

    javac generated/*

    This will create classes files of all the java files generated.

  2. Lastly, from the command prompt, use

    jar cvf test.jar generated/*

    This will create the jar with all the classes.

  1. 从命令提示符使用 -

    javac生成/*

    这将创建所有生成的 java 文件的类文件。

  2. 最后,在命令提示符下,使用

    jar cvf test.jar 生成/*

    这将创建包含所有类的 jar。

回答by aviad

  1. Put your xsd file in some directory (call it resources for example)

  2. In command line navigate to the directory where the resources dir is located.

  3. Run jar cf jar-file %input-file_name%(input-file-name is 'resources' in your case)

  1. 将您的 xsd 文件放在某个目录中(例如将其称为资源)

  2. 在命令行中导航到资源目录所在的目录。

  3. 运行jar cf jar-file %input-file_name%(在您的情况下,输入文件名是“资源”)

Read more here.

在这里阅读更多。

I believe there are more elegant ways to ship static content (which the xsd is) However, you do not want to disclose your goal so that is how you create the jar.

我相信有更优雅的方式来传送静态内容(xsd 就是这样)但是,您不想透露您的目标,所以这就是您创建 jar 的方式。

Good luck!

祝你好运!