xjc(1)
π xjc(1) β the Java Web Services Tools glow-up β¨
okay bestie, sit down, hydrate, because we're about to talk about xjc, aka the little compiler from the Java Web Services Tools corner of your JDK that turns your XML schema into fully annotated Java classes. it's giving "glow-up fairy godmother but for .xsd files". no cap.
πΈ NAME πΈ
xjc β compiles an XML schema file into fully annotated Java classes. that's it. that's the whole job. iconic behavior honestly.
π SYNOPSIS π
xjc [ options ] schema file/URL/dir/jar ... [-b bindinfo ] ...
optionsβ the command-line options. peep the OPTIONS section below, we get into all of them.schema file/URL/dir/jar ...β where your XML schema lives. if you hand it adir, then literally all the schema files in it get compiled. if you hand it ajar, then the/META-INF/sun-jaxb.episodebinding file is what gets compiled. π«Ά-b bindinfoβ the location of the bindings files.
π¦ DESCRIPTION π¦
so first thing: you start the binding compiler with the appropriate xjc shell script sitting in the bin directory for your platform. that's your entry point, that's your girl.
there's also an Ant task to run the binding complier (yes, they wrote "complier", we're keeping it, it's part of the lore π). see Using the XJC with Ant at http://jaxb.java.net/nonav/2.1.3/docs/xjcTask.html.
β¨ OPTIONS β¨
- See also Nonstandard Options
- See also Deprecated and Removed Options
-nvβ okay so by default the XJC binding compiler does strict validation of the source schema before it processes anything. use this option to turn that strict schema validation off. and no, that does not mean the binding compiler stops validating entirely β it just means it does a less-strict validation instead. vibe check: relaxed, not lawless.-extensionβ by default the XJC binding compiler strictly enforces the rules laid out in the Compatibility chapter of the JAXB Specification. Appendix E.2 defines a whole set of W3C XML Schema features that are not completely supported by JAXB v1.0. in some cases you may be allowed to use them in the-extensionmode that this switch enables. in the default (strict) mode you're also limited to using only the binding customization defined in the specification. flip on-extensionand suddenly you're allowed to use the JAXB Vendor Extensions. it's giving "rules are made to be... extended" π-b fileβ specifies one or more external binding files to process. each binding file needs its own-bswitch, no sharing. the syntax of external binding files is flexible, so you've got options: you can have a single binding file that contains customization for multiple schemas, or you can break the customization into multiple bindings files:
xjc schema1.xsd schema2.xsd schema3.xsd -b bindings123.xjbxjc schema1.xsd schema2.xsd schema3.xsd -b bindings1.xjb -b bindings2.xjb -b bindings3.xjb
plus, the ordering of the schema files and binding files on the command line does not matter. chaos-friendly. we love that for us.
-d dirβ by default the XJC binding compiler generates the Java content classes in the current directory. use this to specify an alternate output directory instead. β οΈ the output directory must already exist β the XJC binding compiler will not create it for you. bestie it is not your mom, make the folder yourself.-p pkgβ when you specify a target package with this command-line option, it overrides any binding customization for the package name and the default package name algorithm defined in the specification. main character energy:-pgoes first in line, periodt.-httpproxy proxyβ specifies the HTTP or HTTPS proxy, in this format:[user[:password]@]proxyHost[:proxyPort]. the old-hostand-portoptions are still supported by the RI for backward compatibility, but they were deprecated. π¨ and listen: the password you specify with this option is an argument that is visible to other users who use thetopcommand. for greater security, use the-httpproxyfileoption instead. protect your password, queen.-httpproxyfile fileβ specifies the HTTP or HTTPS proxy with a file instead. same format as the-httpproxyoption, but the password specified in the file is not visible to other users. stealth mode: engaged. π₯·-classpath argβ specifies where to find client application class files used by thejxb:javaTypeandxjc:superClasscustomization.-catalog fileβ specifies catalog files to resolve external entity references. supports the TR9401, XCatalog, and OASIS XML Catalog formats. see XML Entity and URI Resolvers athttp://xerces.apache.org/xml-commons/components/resolver/resolver-article.html.-readOnlyβ by default the XJC binding compiler does not write-protect the Java source files it generates. use this option to force it to mark the generated Java sources as read-only. lock them in, they're done, nobody touch them π-npaβ suppresses the generation of package level annotations into**/package-info.java. using this switch causes the generated code to internalize those annotations into the other generated classes.-no-headerβ suppresses the generation of a file header comment that includes some note and time stamp. using this makes the generated code more compatible with thediffcommand. yes,diff-friendly output is a love language.-target 2.0β avoids generating code that relies on any JAXB 2.1 features. this will allow the generated code to run with a JAXB 2.0 runtime environment (such as Java SE 6). time travel but make it build-compatible.-xmlschemaβ treats input schemas as W3C XML Schema (default). if you don't specify this switch, then your input schemas are treated as though they are W3C XML Schemas. so... same thing either way. it's the default's default. iconic of it.-relaxingβ treats input schemas as RELAX NG (experimental and unsupported). support for RELAX NG schemas is provided as a JAXB Vendor Extension. β οΈ experimental. unsupported. you've been warned, bestie.-relaxing-compactβ treat input schemas as RELAX NG compact syntax (experimental and unsupported). support for RELAX NG schemas is provided as a JAXB Vendor Extension.-dtdβ treats input schemas as XML DTD (experimental and unsupported). support for RELAX NG schemas is provided as a JAXB Vendor Extension. (yes, it says RELAX NG here even though this is the DTD flag. that's what the page says. we don't make the rules, we just compile them π)-wsdlβ treats input as WSDL and compiles schemas inside it (experimental and unsupported).-quietβ suppress compiler output, such as progress information and warnings. silence. serenity. shhh. π€«-verboseβ be extra verbose, such as printing informational messages or displaying stack traces upon some errors. the opposite of the previous one. pick your fighter.-helpβ displays a brief summary of the compiler switches. your little cheat sheet.-versionβ displays the compiler version information. know your era.schema file/URL/dirβ specifies one or more schema files to compile. if you specify a directory, then thexjccommand scans it for all schema files and compiles them. one directory, whole roster, no one left behind. π«Ά
π NONSTANDARD OPTIONS π
-XLocatorβ causes the generated code to expose SAX Locator information about the source XML in the Java bean instances after unmarshalling. it's giving "receipts for where this came from".-Xsync-methodsβ causes all of the generated method signatures to include thesynchronizedkeyword. every single one. yes, all of them. synchronized slay.-mark-generatedβ marks the generated code with the annotation@javax.annotation.Generated. leave a little signature, you earned it. β¨-episode fileβ generates the specified episode file for separate compilation.
π DEPRECATED AND REMOVED OPTIONS π
these are the ghosts of options past. some are just hanging around for backward compatibility, some got fully removed. tread carefully.
-host&-portβ these options are replaced with the-httpproxyoption. for backward compatibility these options are supported, but they will not be documented and might be removed from future releases. living on borrowed time, fr fr.-use-runtimeβ because the JAXB 2.0 specification has defined a portable runtime environment, it is no longer necessary for the JAXB RI to generate**/impl/runtimepackages. therefore this switch is obsolete and was removed. it's gone, bestie, it's in the vault.-sourceβ the-sourcecompatibility switch was introduced in the first JAXB 2.0 Early Access release. this switch is removed from future releases of JAXB 2.0. if you need to generate 1.0.x code, then use an installation of the 1.0.x code base. do not come for this flag, it does not exist anymore. π
π COMPILER RESTRICTIONS π
in general, it is safest to compile all related schemas as a single unit with the same binding compiler switches. like, do the group project in one sitting with one set of rules. keep the following list of restrictions in mind when running the xjc command. most of these issues only apply when you compile multiple schemas with multiple invocations of the xjc command. iykyk.
to compile multiple schemas at the same time, keep these precedence rules for the target Java package name in mind:
- The
-poption has the highest precedence. it's the queen of the stack. jaxb:packagecustomization.- If
targetNamespaceis declared, then apply thetargetNamespaceto the Java package name algorithm defined in the specification. - If no
targetNamespaceis declared, then use a hard coded package namedgenerated.
you cannot have more than one jaxb:schemaBindings per name space, so it is impossible to have two schemas in the same target name space compiled into different Java packages. that's just not happening, sorry babe.
all schemas being compiled into the same Java package must be submitted to the XJC binding compiler at the same time. they cannot be compiled independently and work as expected. no splitting up, no "we'll do it later", it's a package, it's a unit, it's a family. π«Ά
element substitution groups that are spread across multiple schema files must be compiled at the same time. same energy.
π₯ SEE ALSO π₯
- Binding Compiler (xjc) at
http://jaxb.java.net/nonav/2.2.3u1/docs/xjc.html - Java Architecture for XML Binding (JAXB) at
http://www.oracle.com/technetwork/articles/javase/index-140168.html
and that's the whole page, bestie!! π this little baddie ships with JDK 8, dated 21 November 2013 β yes she's vintage, yes she still eats. go compile something gorgeous with her. mwah. πβ¨π¦
π¦ where this page comes from
- alpine 3.24: openjdk8-doc 8.492.09-r0 Β· custom
- ubuntu jammy: openjdk-8-jdk-headless 8u312-b07-0ubuntu1
- ubuntu jammy: openjdk-8-jdk-headless 8u504-ga-1ubuntu1~22.04.3
- ubuntu noble: openjdk-8-jdk-headless 8u402-ga-8build1
- ubuntu noble: openjdk-8-jdk-headless 8u504-ga-1ubuntu1~24.04.3
- ubuntu questing: openjdk-8-jdk-headless 8u462-ga-1
- ubuntu questing: openjdk-8-jdk-headless 8u492-ga~us2-0ubuntu1~25.10.1
- ubuntu resolute: openjdk-8-jdk-headless 8u482-ga~us1-0ubuntu1
- ubuntu resolute: openjdk-8-jdk-headless 8u504-ga-1ubuntu1~26.04.3
- ubuntu stonking: openjdk-8-jdk-headless 8u504-ga-1ubuntu1
- Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms