So I was trying to figure it for a while. I have a Java class with JAXB annotations:
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Book {
private String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
I can then run schemagen
as follows:
schemagen -d d:\Temp Book.java
and the XML schema is generated: schema1.xsd
. And the return code is 0 (tried both windows (echo %ERRORLEVEL%
) and linux (echo $?
).
Now I need to add some Jackson annotation to this class so I am adding a single JSON attribute:
import javax.xml.bind.annotation.XmlRootElement;
import com.fasterxml.jackson.annotation.JsonProperty;
@XmlRootElement
public class Book {
@JsonProperty("title")
private String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
Unfortunately, now when I run schemagen it appears it succeeds (schema file is generated) but the return code is 1 (both on Linux and Windows) which is problematic for me as it causes gmake to fail.
Sadly schemagen
does not output any error messages. But my suspicion is that it cannot find jackson jars so I copied jackson-annotation jar (with dependencies of jackson-core and jackson-databind) to common D:\Temp location and run schemagen
as follows:
schemagen -cp d:\Temp -d d:\Temp Book.java
unfortunately same results, if I run it like this:
schemagen -cp d:\Temp\* -d d:\Temp Book.java
I will also get single null
outputed on console (JAXB guys really emphasized verbosity here) and return code of -1.
How to get schemagen run successfully (return code 0) with Jackson annotations? Any suggestions?
Ok, with a little help from a friend I know how actual command should look like:
schemagen -cp D:\Temp\jackson-annotations-2.5.4.jar -d D:\Temp Book.java
Turns out we need to specify only jackson annotations jar, and not the dependent jars. Also it is not apparent in this simplified scenario, but if you are passing multiple sources on the classpath (-cp parameter) on Linux, those need to be separated with colons and not semi-colons. Basically that was the issue that sent me on the wild goose chase.