You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "KARR, DAVID" <dk...@att.com> on 2015/01/15 16:04:06 UTC

How to build a CXF JAX-RS app with Gradle?

I have a CXF JAX-RS app that is being built with Maven.  I'm looking at converting the build to Gradle.

I noticed the "gradle-jaxb-plugin" on github, which lets me run "xjc".  However, I need one jaxb extension, and that doesn't provide access to extensions yet.

My Maven build currently uses "cxf-xjc-plugin" to run xjc.  What does this do that is specific to CXF that "vanilla" xjc wouldn't do?

Overall, I guess examples like this come close to "manually" calling xjc in Gradle: http://stackoverflow.com/questions/8158453/howto-generate-classes-from-wsdl-and-xsd-with-gradle-equivalent-to-maven-jaxb2 .  It doesn't cover adding extensions, which I guess is just adding to the classpath and command-line arguments.

Has anyone gone down this path who can provide examples?

Re: How to build a CXF JAX-RS app with Gradle?

Posted by Aaron Titus <at...@fwdco.com>.
>
> Actually, I now see that in the XJC Ant task, there is a nested "arg"
> element, which takes property variations of "line", "value", and "path".
> In that case, I guess I would add something like this to the "ant.xjc"
> element:
>
>     arg(line: "-Xxew")
>     arg(line: "-Xfluent-api")
>
> If I needed to add "-Xxew -Xfluent-api" to the XJC command line.  Will
> this work?
>


I cannot say for sure as I haven't tried this, but it seems like its worth
a try to me.

RE: How to build a CXF JAX-RS app with Gradle?

Posted by "KARR, DAVID" <dk...@att.com>.
> -----Original Message-----
> From: Aaron Titus [mailto:atitus@fwdco.com]
> Sent: Thursday, January 15, 2015 1:00 PM
> To: users@cxf.apache.org
> Subject: Re: How to build a CXF JAX-RS app with Gradle?
> 
> On Thu, Jan 15, 2015 at 12:49 PM, KARR, DAVID <dk...@att.com> wrote:
> 
> > > -----Original Message-----
> > > From: Aaron Titus [mailto:atitus@fwdco.com]
> > > Sent: Thursday, January 15, 2015 9:45 AM
> > > To: users@cxf.apache.org
> > > Subject: Re: How to build a CXF JAX-RS app with Gradle?
> > >
> > > >
> > > > I can see how you would add to the xjc classpath to provide
> extensions,
> > > > but how would you specify extension command-line arguments?
> > > >
> > >
> > > The only kind of extensions I've used are the ones that go in a
> binding
> > > file.  How are the extension arguments different than regular command
> > line
> > > arguments?  The example shows how regular arguments work, wouldn't it
> > just
> > > be adding a few more?
> >
> > You show adding arguments to the WSDL task, but not the XJC task.
> >
> 
> 
> I guess I am not sure how to answer your question. I posted two examples I
> had, one showing java exec directly and one via Ant. The xjc is using the
> Ant task. When you say "extension command line arguments" this makes me
> think you want a java exec task, with arguments, as I have shown.
> 
> Do you have an existing Ant task that does what you want?  If you do, post
> it here and maybe I can figure the syntax.  I'm not a maven user, so I
> can't help interpret going directly from maven to gradle.
> 
> The wsdl task is a pure java exec.  If you want to run xjc directly (skip
> the ant task) then you could build up a task that does it along the lines
> of what I did here with wsdl2java.

Actually, I now see that in the XJC Ant task, there is a nested "arg" element, which takes property variations of "line", "value", and "path".  In that case, I guess I would add something like this to the "ant.xjc" element:

    arg(line: "-Xxew")
    arg(line: "-Xfluent-api")

If I needed to add "-Xxew -Xfluent-api" to the XJC command line.  Will this work?

Re: How to build a CXF JAX-RS app with Gradle?

Posted by Aaron Titus <at...@fwdco.com>.
On Thu, Jan 15, 2015 at 12:49 PM, KARR, DAVID <dk...@att.com> wrote:

> > -----Original Message-----
> > From: Aaron Titus [mailto:atitus@fwdco.com]
> > Sent: Thursday, January 15, 2015 9:45 AM
> > To: users@cxf.apache.org
> > Subject: Re: How to build a CXF JAX-RS app with Gradle?
> >
> > >
> > > I can see how you would add to the xjc classpath to provide extensions,
> > > but how would you specify extension command-line arguments?
> > >
> >
> > The only kind of extensions I've used are the ones that go in a binding
> > file.  How are the extension arguments different than regular command
> line
> > arguments?  The example shows how regular arguments work, wouldn't it
> just
> > be adding a few more?
>
> You show adding arguments to the WSDL task, but not the XJC task.
>


I guess I am not sure how to answer your question. I posted two examples I
had, one showing java exec directly and one via Ant. The xjc is using the
Ant task. When you say "extension command line arguments" this makes me
think you want a java exec task, with arguments, as I have shown.

Do you have an existing Ant task that does what you want?  If you do, post
it here and maybe I can figure the syntax.  I'm not a maven user, so I
can't help interpret going directly from maven to gradle.

The wsdl task is a pure java exec.  If you want to run xjc directly (skip
the ant task) then you could build up a task that does it along the lines
of what I did here with wsdl2java.

RE: How to build a CXF JAX-RS app with Gradle?

Posted by "KARR, DAVID" <dk...@att.com>.
> -----Original Message-----
> From: Aaron Titus [mailto:atitus@fwdco.com]
> Sent: Thursday, January 15, 2015 9:45 AM
> To: users@cxf.apache.org
> Subject: Re: How to build a CXF JAX-RS app with Gradle?
> 
> >
> > I can see how you would add to the xjc classpath to provide extensions,
> > but how would you specify extension command-line arguments?
> >
> 
> The only kind of extensions I've used are the ones that go in a binding
> file.  How are the extension arguments different than regular command line
> arguments?  The example shows how regular arguments work, wouldn't it just
> be adding a few more?

You show adding arguments to the WSDL task, but not the XJC task.

Re: How to build a CXF JAX-RS app with Gradle?

Posted by Aaron Titus <at...@fwdco.com>.
>
> I can see how you would add to the xjc classpath to provide extensions,
> but how would you specify extension command-line arguments?
>

The only kind of extensions I've used are the ones that go in a binding
file.  How are the extension arguments different than regular command line
arguments?  The example shows how regular arguments work, wouldn't it just
be adding a few more?

RE: How to build a CXF JAX-RS app with Gradle?

Posted by "KARR, DAVID" <dk...@att.com>.
> -----Original Message-----
> From: Aaron Titus [mailto:atitus@fwdco.com]
> Sent: Thursday, January 15, 2015 9:16 AM
> To: users@cxf.apache.org
> Subject: Re: How to build a CXF JAX-RS app with Gradle?
> 
> Yep, I have this working here.  I just made a task that calls xjc or
> wsdl2java as needed. Here are some examples:
> 
> 
> 
> task linkWsdlToJavaClient(type:JavaExec) {
> 
>      main = "org.apache.cxf.tools.wsdlto.WSDLToJava"
>      classpath = sourceSets.main.runtimeClasspath
> 
>      args "-d", "src3/main/java"
>      args "-p", "com.example"
>      args "-client", "src/samples/example1.wsdl"
> }
> 
> 
> task jaxbLinkRequest() << {
> 
>     ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask',
>                 classpath: configurations.jaxb.asPath)
> 
>         ant.xjc(destdir: 'src4',
>                 package: 'com.example',
>                 extension: 'true') {
> 
>             schema(dir: 'src/samples',
>                    includes: 'example1.xsd,example2.wsdl')
> 
>         }
> 
> }

I can see how you would add to the xjc classpath to provide extensions, but how would you specify extension command-line arguments?

> On Thu, Jan 15, 2015 at 10:04 AM, KARR, DAVID <dk...@att.com> wrote:
> 
> > I have a CXF JAX-RS app that is being built with Maven.  I'm looking at
> > converting the build to Gradle.
> >
> > I noticed the "gradle-jaxb-plugin" on github, which lets me run "xjc".
> > However, I need one jaxb extension, and that doesn't provide access to
> > extensions yet.
> >
> > My Maven build currently uses "cxf-xjc-plugin" to run xjc.  What does
> this
> > do that is specific to CXF that "vanilla" xjc wouldn't do?
> >
> > Overall, I guess examples like this come close to "manually" calling xjc
> > in Gradle:
> > http://stackoverflow.com/questions/8158453/howto-generate-classes-from-
> wsdl-and-xsd-with-gradle-equivalent-to-maven-jaxb2
> > .  It doesn't cover adding extensions, which I guess is just adding to
> the
> > classpath and command-line arguments.
> >
> > Has anyone gone down this path who can provide examples?
> >

RE: How to build a CXF JAX-RS app with Gradle?

Posted by "KARR, DAVID" <dk...@att.com>.
> -----Original Message-----
> From: Aaron Titus [mailto:atitus@fwdco.com]
> Sent: Thursday, January 15, 2015 9:16 AM
> To: users@cxf.apache.org
> Subject: Re: How to build a CXF JAX-RS app with Gradle?
> 
> Yep, I have this working here.  I just made a task that calls xjc or
> wsdl2java as needed. Here are some examples:
> 
> task jaxbLinkRequest() << {
> 
>     ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask',
>                 classpath: configurations.jaxb.asPath)
> 
>         ant.xjc(destdir: 'src4',
>                 package: 'com.example',
>                 extension: 'true') {
> 
>             schema(dir: 'src/samples',
>                    includes: 'example1.xsd,example2.wsdl')
> 
>         }
> 
> }

My task looks like this:
-------------------------
task processXSDs() << {
	ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask',
				classpath: configurations.jaxb.asPath)
	ant.xjc(destdir: 'tmp', package: "com.att.sunlight.service.domain.serviceCallResults", extension: true) {
		classpath(path: configurations.jaxb.asPath)
		schema(dir: "src/main/resources/schema", includes: "serviceCallResults.xsd")
        arg(value: "-Xxew")
        arg(value: "-summary target/xew-summary.txt")
        arg(value: "-instantiate lazy")
        arg(value: "-Xfluent-api")
	}
}
-------------

Where I added the following to the jaxb configuration:
	jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.6'
	jaxb 'com.sun.xml.bind:jaxb-impl:2.2.6'
	jaxb 'javax.xml.bind:jaxb-api:2.2.6'
	jaxb "JAXBXMLElementWrapperPlugin:JAXBXMLElementWrapperPlugin:1.0.0"
	jaxb "net.java.dev.jaxb2-commons:jaxb-fluent-api:2.1.8"

Unfortunately, I'm still having trouble with extensions.  This is failing with this:
--------------------
Caused by: java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: Provider dk.conspicio.jaxb.plugins.XmlElementWrapperPlugin not a subtype
	at com.sun.tools.xjc.Options.findServices(Options.java:965)
	at com.sun.tools.xjc.Options.getAllPlugins(Options.java:383)
--------------------

I can't even figure out what that error message means.  I even decompiled the "Options" class from the jar I assume this is coming from, and I can't find that exception being thrown at that line.

> On Thu, Jan 15, 2015 at 10:04 AM, KARR, DAVID <dk...@att.com> wrote:
> 
> > I have a CXF JAX-RS app that is being built with Maven.  I'm looking at
> > converting the build to Gradle.
> >
> > I noticed the "gradle-jaxb-plugin" on github, which lets me run "xjc".
> > However, I need one jaxb extension, and that doesn't provide access to
> > extensions yet.
> >
> > My Maven build currently uses "cxf-xjc-plugin" to run xjc.  What does
> this
> > do that is specific to CXF that "vanilla" xjc wouldn't do?
> >
> > Overall, I guess examples like this come close to "manually" calling xjc
> > in Gradle:
> > http://stackoverflow.com/questions/8158453/howto-generate-classes-from-
> wsdl-and-xsd-with-gradle-equivalent-to-maven-jaxb2
> > .  It doesn't cover adding extensions, which I guess is just adding to
> the
> > classpath and command-line arguments.
> >
> > Has anyone gone down this path who can provide examples?
> >

Re: How to build a CXF JAX-RS app with Gradle?

Posted by Aaron Titus <at...@fwdco.com>.
Yep, I have this working here.  I just made a task that calls xjc or
wsdl2java as needed. Here are some examples:



task linkWsdlToJavaClient(type:JavaExec) {

     main = "org.apache.cxf.tools.wsdlto.WSDLToJava"
     classpath = sourceSets.main.runtimeClasspath

     args "-d", "src3/main/java"
     args "-p", "com.example"
     args "-client", "src/samples/example1.wsdl"
}


task jaxbLinkRequest() << {

    ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask',
                classpath: configurations.jaxb.asPath)

        ant.xjc(destdir: 'src4',
                package: 'com.example',
                extension: 'true') {

            schema(dir: 'src/samples',
                   includes: 'example1.xsd,example2.wsdl')

        }

}


Personally,  I don't run these every build, and I check in the generated
code. This allows me to be able to build an older release exactly as it
was.  If you would rather have it generate every time, you can setup
dependencies so that this task will get run as part of the build.







On Thu, Jan 15, 2015 at 10:04 AM, KARR, DAVID <dk...@att.com> wrote:

> I have a CXF JAX-RS app that is being built with Maven.  I'm looking at
> converting the build to Gradle.
>
> I noticed the "gradle-jaxb-plugin" on github, which lets me run "xjc".
> However, I need one jaxb extension, and that doesn't provide access to
> extensions yet.
>
> My Maven build currently uses "cxf-xjc-plugin" to run xjc.  What does this
> do that is specific to CXF that "vanilla" xjc wouldn't do?
>
> Overall, I guess examples like this come close to "manually" calling xjc
> in Gradle:
> http://stackoverflow.com/questions/8158453/howto-generate-classes-from-wsdl-and-xsd-with-gradle-equivalent-to-maven-jaxb2
> .  It doesn't cover adding extensions, which I guess is just adding to the
> classpath and command-line arguments.
>
> Has anyone gone down this path who can provide examples?
>