19

So I've been looking at interfacing with xml files for a project I've been working on, and one of the things I want to do is generate java classes from a .dtd file. After some searching, I found out that xjc should be able to do what I want, but I cannot for the life of me find out where to get the program itself.

I feel like the answer is sitting right in front of me, but my google-fu is really failing me hardcore right now...

Ross Aiken
  • 912
  • 1
  • 6
  • 16

8 Answers8

28

Note that since Java 11, the JAXB was removed from the JDK. It has to be separately installed. There is a bin directory in the ZIP file where we can find the xjc and schemagen tools.

Download link: https://javaee.github.io/jaxb-v2/

Jan Bodnar
  • 10,969
  • 6
  • 68
  • 77
  • 3
    Beware: `xjc.bat` (of version 2.3.1) contains invalid settings, does not detect Java properly (uses `java` available from path instead of that one specified in `JAVA_HOME` path variable), does not work with Java 9 or later. So first, install java 1.8, then modify `jaxb-ri\bin\xjc.bat` and replace `/lib/` with `/mod/`, replace `%JAXB_HOME%/mod/javax.activation.jar;%JAXB_HOME%/lib/relaxngDatatype.jar` with `%JAXB_HOME%/mod/javax.activation-api.jar;%JAXB_HOME%/mod/relaxng-datatype.jar`, run `set JAVA_HOME=`, then run `bin\xjc.bat` from `jaxb-ri` folder. – izogfif Nov 12 '19 at 12:59
  • A downloaded the old JDK and just ran the command from the bin folder where xcj.exe is located. – Vectoria Aug 04 '20 at 23:24
  • 1
    Optionally you can add an jdk8 (below the jdk 11 or newer reference) to your path and it will be found as well – Valerij Dobler Jun 02 '21 at 13:30
7

I got it when I installed java. It is probably on your system right now. Look in the directory where java, javac, etc are located.

emory
  • 10,725
  • 2
  • 30
  • 58
  • ...wow. It was really that simple. I have two drives, with some of my program files on one and some on the other. I had searched throughout the java folder on my E: drive, which is where the majority of my installations go, but had completely forgotten about the C: drive. Also, as a side note, it looks like it was only in the java jdk folders, so you need the full jdk to make it work (in an effort to make this question at least slightly useful to other people) – Ross Aiken Apr 04 '12 at 06:02
  • 1
    it's not in java/jdk distro starting from 9+ – Bogdan Mar 16 '21 at 14:30
  • @Bogdan For certain questions, I think the answers should be deprecated. I think at the time I wrote this answer I was highly competent in the subject matter, but it has moved so far off my radar that I no longer even understand the question. In general, most answers to technical questions that are over 5 years old should be considered WRONG. – emory Mar 16 '21 at 15:06
4

Its part of the JDK. Check your Java bin folder.

barsju
  • 4,408
  • 1
  • 19
  • 24
1

xjc is a tool in JAXB which is in Java SE, Java EE and Java Web Services and i'm sure many more. Read up on JAXB Here

apesa
  • 12,163
  • 6
  • 38
  • 43
1

I had some problems while installing xjc manually downloaded, as suggested in one of the answers and I succeed with a sudo apt-get install jaxb as suggested by my Linux terminal :)

Frankie Drake
  • 1,338
  • 9
  • 24
  • 40
0

If you are using ubuntu and java version is less than 9, then this may help

$ sudo update-alternatives --install /usr/bin/xjc xjc /your_java_home_path/bin/xjc 100
Martin C.
  • 12,140
  • 7
  • 40
  • 52
0

If you're just looking to parse XML as a one off, and you don't want to deal with downloading random binaries, or messing about with your PATH, you can easily get access to xjc by installing any JDK 1.8 version.

To do this nice and easily, use SDKMAN

Once it's installed, run sdk install java 8.0.332-zulu to install Java 8, you probably don't want to set it as your default, so once the install is done run sdk use java 8.0.332-zulu and you're good to.

Chris
  • 3,437
  • 6
  • 40
  • 73
0

It's available here: https://eclipse-ee4j.github.io/jaxb-ri/ on the Download section

akuma8
  • 4,160
  • 5
  • 46
  • 82