Tuesday, May 3, 2011

How to map map xs:time to java.util.Calendar?

In order to force XJC to generate java.util.Calendar we have some options,one of them is to write customization and import it in our schema or just paste <xs:annotaion> into the schema.
"<xs:schema elementformdefault="qualified" version="1.0" xs="http://www.w3.org/2001/XMLSchema" jaxb="http://java.sun.com/xml/ns/jaxb" targetnamespace="calendar-schemalet">
<xs:annotation><xs:appinfo>
<jaxb:globalbindings>
<jaxb:javatype name="java.util.Calendar" xmltype="xs:date" parsemethod="javax.xml.bind.DatatypeConverter.parseDate" printmethod="javax.xml.bind.DatatypeConverter.printDate">
<jaxb:javatype name="java.util.Calendar" xmltype="xs:time" parsemethod="javax.xml.bind.DatatypeConverter.parseDate" printmethod="javax.xml.bind.DatatypeConverter.printDate">
</jaxb:javatype></jaxb:javatype></jaxb:globalbindings>
</xs:appinfo></xs:annotation>
</xs:schema>"
Now we can import this file , for example :
<xs:import schemalocation="CalendarSchemalet.xsd" namespace="none"></xs:import>
Or we can use xjc compile parameter as following:

<!--?xml version="1.0" encoding="UTF-8"?-->
<jxb:bindings version="2.1" jxb="http://java.sun.com/xml/ns/jaxb" xsd="http://www.w3.org/2001/XMLSchema" xjc="http://java.sun.com/xml/ns/jaxb/xjc">

<jxb:globalbindings>
<xjc:javatype name="java.util.Calendar" xmltype="xsd:time" adapter="com.dpi.ach.cor.model.TimeAdapter">
</xjc:javatype></jxb:globalbindings>
</jxb:bindings>
and save this as binding.xjb, and use the following command:
xjc -p com.mycompany -b binding.xjb -extension test.xsd
that's it.

Monday, April 5, 2010

Making executable Jar file

If a jar file contains an application’s main class, you can make the jar executable. This is a convenience for your users, because with an executable jar they don’t have to remember the name of the main class. To run an executable jar file, you just use the -jar option and name the file on the java command line, like this:

java -jar the_executable_archive.jar

To make an executable jar, first create a manifest that tells which class file is the main class.
To do this, create a text file that contains a line like the following:

Main-Class: x.y.MyMainClass

Note that you specify the class name, not the class filename, so there’s no .class suffix. Be to specify the entire class name, including package prefixes (x.y. in this example). The text can have any name at all. It is not inserted into the jar file. Instead, the jar program reads and copies its information into the manifest file, which the jar program creates.
Now build your jar file, using the -m option to tell jar which file to look in for manifest For if your Main-Class line is in a file called manny.txt, your command would be:
jar -cvfm my_arch.jar manny.txt *.class

The jar program reads the main class declaration in manny.txt and builds a manifest inside the main class declaration and a bit of extra information. Inside the jar a META-INF is created, and in META-INF is a plain-text file called MANIFEST.MF.
Here’s what MANIFEST.MF looks like for our example:

Manifest-Version: 1.0
Created-By: 1.5.0 (Sun Microsystems Inc.)
Main-Class: MyMainClass

Ease of use is an important part of software quality. A little familiarity with the jar program
increase the ease of use of your project.

Thanks to "Complete Java® 2 Certification: Study Guide, " Written by "Philip Heller,Simon Roberts"