dev@fi.java.net

FYI: how to put build id into a jar

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 04 Aug 2005 09:44:27 -0700

I modified the Hudson configuration to pass in "build.id" property to
the Ant build. So the rest is just to hook it up to the jar task.

In JAXB RI, we have:

         <!-- this property is used by "xjc -version" and is also set in
each of the
              generated ObjectFactory classes. It should be set via the
RE build
              scripts via 'ant -Dbuild.id="b08"' otherwise the current
date and time
              will be used -->
         <tstamp>
             <format property="now" pattern="MM/dd/yyyy hh:mm aa"
unit="hour"/>
         </tstamp>
         <property name="build.id" value="${now}(${user.name})" />
         <property name="build.version"
value="${release.impl.version}-${build.id}-${release.impl.version.suffix}"
/>
         <echo message="The build id is: ${build.version}" />


Then use the following task to put this into the manifest:

               <manifest mode="update"
file="${runtime.root}/build/manifest.rt">
                 <section name="com.sun.xml.bind.v2.runtime">
                   <attribute name="Implementation-Version"
value="${build.version}" />
                 </section>
               </manifest>

This makes sure that the property is set to some value no matter where
it run (RE and Hudson gets serial numbers.)

This can be obtained as:

        // any class in the com.sun.xml.bind.v2.runtime package
        JAXBContextImpl.class.getPackage().getImplementationVersion()

We also bake this into Messages.properties so that "xjc -version" prints
this build id. We also define a method on JAXBContext that returns this
value.



-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com