Thank you very much.
This works:
xjcOutput=path_to('target/generated-sources/xjc')
xjc = file(xjcOutput => sources) do |dir|
ant('xjc') do |ant|
mkdir_p xjcOutput
cp = Buildr.artifacts("javax.xml.bind:jaxb-api:jar:2.2.1",
"com.sun.xml.bind:jaxb-impl:jar:2.2.1",
"com.sun.xml.bind:jaxb-xjc:jar:2.2.1").each(&
:invoke).map(& :name).join(File::PATH_SEPARATOR)
ant.taskdef :name=>"xjc", :classname=>"com.sun.tools.xjc.XJCTask",
:classpath=>cp
ant.xjc :schema=>path_to("src/main/resources/c.xsd"),
:destdir=>path_to(xjcOutput), :package=>"org.foo.api"
end
end
How does it look?
I'm not really sure what "file(xjcOutput => sources)" actually does, or how to
interpret it; back to the Pickaxe book!
On Aug 26, 2010, at 8:27 PM, Antoine Toulme wrote:
> Hello Marc,
>
> a few remarks:
> 1. "#{xjcOutput}" is equivalent to xjcOutput. That should simplify your
> code.
> 2. Why bother with mentioning local artifacts ? Do you know which jar you
> need ? Are they hosted on a maven repository ?
> If yes, you can do :classpath=>
> Buildr.artifacts("com.sun.jaxb:jaxb:jar:1.2.3",
> "com.sun.jaxb:jaxb-impl:jar:1.2.3").map(&:to_s).join(File::PATH_SEPARATOR)
> Your code will work on any machine then.
>
>
> On Thu, Aug 26, 2010 at 18:53, Mark Petrovic <[email protected]> wrote:
>
>> Hi. I'm new to Buildr, coming from Ant and Maven. I've read the black
>> Buildr book, and now I'm attempting to do some simple stuff with the JAXB
>> XJC task. Here's what I have so far:
>>
>> ...
>> compile :xjc
>> package :jar, :id => 'vzapi'
>>
>> task :xjc do
>> begin
>> ant('xjc') do |ant|
>> xjcOutput='target/generated-sources/xjc'
>> rm_rf "#{xjcOutput}"
>> mkdir_p "#{xjcOutput}"
>>
>> t=Dir.entries("#{ENV['HOME']}/tools/jaxb-ri/lib").join(File::PATH_SEPARATOR)
>> puts t
>> ant.taskdef :name=>"xjc",
>> :classname=>"com.sun.tools.xjc.XJCTask", :classpath=>"#{t}"
>> ant.xjc :schema=>"src/main/resources/c.xsd",
>> :destdir=>"#{xjcOutput}", :package=>"org.foo.api"
>> end
>> end
>> end
>>
>> where you can see my horribly clumsy, two-left-foot attempts to put
>> together a classpath for the Ant taskdef. The JAXB jars are in
>> ENV['HOME']}/tools/jaxb-ri/lib/*.jar.
>>
>> Can someone suggest the "Buildr way" to build this classpath? I've studied
>> the examples referred to here
>> http://www.mail-archive.com/[email protected]/msg01115.html but I'm
>> still not quite getting it. I'm learning Ruby as I go, having read the
>> Pickaxe book, but where not a lot of it has sunk in yet.
>>
>> Thanks!
>>
>> --
>> Mark Petrovic
>>
>>
>>
--
Mark Petrovic