Thursday, October 21, 2010

JAXB Serializable Binding with Maven

Generating the classes from a xsd where the classes implement the java.io.Serializable interface for serialization between nodes.

.   ---> pom.xml
./.settings
./src
./src/main
./src/main/binding
    ---> binding.xjb
./src/main/java
./src/main/java/com
./src/main/java/META-INF
./src/main/resources
    ---> my.xsd

The maven plugin configuration in the pom.xml
<plugins>
            <plugin>
                <groupid>org.jvnet.jaxb2.maven2</groupid>
                <artifactid>maven-jaxb2-plugin</artifactid>
                <version>0.7.4</version>
                <configuration>
                    <extension>true</extension>
                    <args>
                        <arg>-Xfluent-api</arg>
                    </args>
                    <schemadirectory>src/main/resources</schemadirectory>
                    <bindingdirectory>src/main/binding</bindingdirectory>
                    <plugins>
                        <plugin>
                            <groupid>net.java.dev.jaxb2-commons</groupid>
                            <artifactid>jaxb-fluent-api</artifactid>
                            <version>2.1.8</version>
                        </plugin>
                    </plugins>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

The content of the binding.xjb
<jxb:bindings 
    version="1.0" 
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jxb:extensionBindingPrefixes="xjc">
    <jxb:bindings>
        <jxb:globalBindings>
            <xjc:serializable/>
        </jxb:globalBindings>
    </jxb:bindings>
</jxb:bindings>

The result:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "application", propOrder = {
"name",
"version",
"state",
"serverName"
})
public class Application
implements Serializable
{

@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected String version;
@XmlElement(required = true)
protected String state;

Wednesday, October 13, 2010

Displaying MANIFEST.MF of multiple jars in directory

Oneliner for bash to dump the MANIFEST.MF information per jar.
find . -name '*.jar' -type f | while read dir; do [ -f META-INF/MANIFEST.MF ] && rm -f META-INF/MANIFEST.MF;echo $dir; md5sum $dir;jar xfv $dir META-INF/MANIFEST.MF; cat META-INF/MANIFEST.MF; done

On MacOSX the md5sum would be md5, and if you do not have the jar util... here the unzip version.. .
find . -name '*.jar' -type f | while read dir; do [ -f META-INF/MANIFEST.MF ] && rm -f META-INF/MANIFEST.MF;echo $dir; md5 $dir;unzip $dir META-INF/MANIFEST.MF; cat META-INF/MANIFEST.MF; done