简体   繁体   中英

How to create a jar file from xsd

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

Can anyone please explain the process?

You can use the following steps if you are not using mavne to generate 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

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

xjc -p test Test.xsd

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

  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.

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

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.html and Maven will package everything to JAR then.

  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)

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.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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