Generation of jaxb groovy classes from xsd - groovy

We have generated jaxb java classes from xsd for our java project.Now can we generate jaxb groovy classes for our new groovy project using xsd? If yes how to generate them?

XJC compiler doesn't support Groovy. What's wrong with just Java files? Just keep them separate in your project and everything should be fine. It's ok to mix Java and Groovy in one projects:
src
main
groovy <<< your Groovy code
resources
generated
java <<< XJC generated classes go here

Related

How can I use Groovy classes in other packages without JAR?

I'm pretty new to Groovy (coming from Java), so this may be a stupid question :-)
Nonetheless: I'd like to structure a couple of Groovy scripts using packages. And I'd like to import some general Groovy classes from some other package.
How can I make sure that my Groovy scripts finds the other classes in the other packages? The only classpath related files I can remember are JARs.
If you from java:
Groovy loads classes as java and also includes non-compiled with extension .groovy.
So, you have to place your classes relative to classpath according to their package name.
The command line should be something like this:
groovy -cp "path_to_classes_root" "path_and_name_of_main_groovy_script.groovy"

Groovy-Eclipse 2.5.2: java.lang.ClassNotFoundException: picocli.CommandLine$ParameterException

I'm using Eclipse 4.5 with the Groovy-Eclipse 2.9.2/4.5 plugin which I thought was supposed to have the Groovy 2.5 compiler. However, it didn't have any picocli support so I added the groovy-cli-picocli-2.5.2-indy.jar to my classpath and was able to compile. However #2, when trying to run the script via Eclipse I get:
java.lang.ClassNotFoundException: picocli.CommandLine$ParameterException
It looks like groovy-cli-picocli-2.5.2-indy.jar does not have CommandLine class at all.
I would just throw jars at this from the fullblown picocli distribution but I'm under the impression they all have to somehow wrap nicely into Eclipse Groovy library via groovy.cli.picocli.CliBuilder.
Is my Groovy 2.5.2 missing this or am I somehow missing the boat on how it's supposed to work because picocli is not working for me in this configuration. Thanks!
You are correct: groovy-cli-picocli-2.5.2.jar (and groovy-cli-picocli-2.5.2-indy.jar) do not contain the picocli classes.
You need to add the picocli jar to the classpath.
If you use Maven, the groovy-all POM should include all dependencies.
(My original answer mentioned picocli classes that are shaded into the groovy-2.5.x.jar under the groovyjarjarpicocli package but these are intended for use internally by Groovy and not meant to be used by applications.)

Java 8 Javadoc vs. XJC Warnings & Errors

How do I use xjc to generate Java code from xsd files which have 0 Javadoc Warnings and Errors at build time when using Java 8 and not changing which Doclint being used?
I'm using an Apache-Ant build.xml file to build the codebase.
I can't.
According to JAXB, those build problems are not blockers, "since workaround is to pass -Xdoclint:none to javadoc executable". =(
Yes, it is possible to hand-edit the generated Java files to get 0 Warnings and 0 Errors, but my main goal is to generate Java files that do not require hand edits (or custom plugins) under any and all circumstances.

complex jaxb scenario on generation of java objects

I have a project that does JAXB generation with framework.xsd. This generates a jar with the xsd and the jaxb objects and other classes around that stuff.
Then another group(two different groups) will be extending framework.xsd and subxmling using the schema extends stuff to extend objects in framework.xsd. They also want to generate jaxb objects BUT they want their SomeClass.java to obviously extend my Framework.java and don't want to end up with a whole new heirarchy.
Is this even possible?
How to do something like this? as the solution would need to
tell the jaxb compiler that the namespace yy is already generated so do not generate
tell the jaxb compiler that it needs to refer to the classes in the package zzzzzz or to look at the xjb file from the framework jar file or something.
Is this possible?
thanks,
Dean
You want to use an episode file : http://weblogs.java.net/blog/kohsuke/archive/2006/09/separate_compil.html when generating JAXB classes for your first schema.
$ xjc -episode framework.episode framework.xsd
Then the other group that consumes your framework.jar should:
1) import your schema in their own schema e.g.:
<xsd:import namespace="http://www.myorg.com/framework" schemaLocation="framework.xsd"/>
2) generate their JAXB classes
$ xjc extend.xsd -b framework.episode
(they'll need a copy of your xsd and episode file at xjc time, as well as the framework.jar in the classpath)
Note that according to the blog post above, you can also place the framework.episode file inside your jar (e.g. /META-INF/sun-jaxb.episode for JAXB RI at least - other JAXB impl may have other ways of accomplishing the same thing), so that the -b framework.episode option can be omitted. I personally find it a bit impractical, you still need the XSD anyway.

JAXB : use local schemaLocation to generate Java classes

I am trying to generate Java classes from a XSD schema using the xjc command that comes with JAXB.
My schema looks like:
<xs:schema xmlns="..."
xmlns:ext="http://schemas.myco.com/ext" ... >
<xs:import namespace="http://schemas.myco.com/ext"
schemaLocation="http://myco.com/schemas/ext.xsd"/>
...
The problem is that the schemaLocation URI does not exist and I can not modify the XSD file. That is why the generation process fails with errors such as "src-resolve: Cannot resolve the name 'ext:Resource_Type' to a(n) 'type definition' component".
Is there any way to force JAXB to use a local copy of ext.xsd file during the process without modifying the original XSD file ?
Two possible solutions:
JAXB Episode File:
http://weblogs.java.net/blog/2006/09/05/separate-compilation-jaxb-ri-21
or
XML Catalogs (search Google)

Resources