January 2008
Monthly Archive
Thu 31 Jan 2008
Problem:Create an XML Schema which will be binded by JAXB to a class structure following certain constrains. You have certain degrees of freedom for your schema design and later you might also use schema annotations provided by JAXB. Modularize your XML schemas, simplest example is: A.xsd uses <include> to include declarations from schema B.xsd.
I want to try Netbeans’ excellent schema design features. Eventually I want to publish the schemas in a WAR deployed in a web container. That’s why I decided to put the files directly into the /web directory of the web-project.
Proposed Solution:
Trying to use Netbeans’ JAXB Wizard (or see http://wiki.netbeans.org/JAXBWizard) to create a JAXB Binding for A.xsd you will meet certain limitations: schema file changes won’t be visible to the “Regenerate” operation. You could edit the copy of A.xsd created by the JAXB Wizard in src/conf/xml-resources/jaxb/name_of_the_binding to make changes visible to the task but that will not see changes in B.xsd. The reason is that the ant tasks created by the JAXB Wizard do not provide this kind of granularity.
So the solution for me was to create the binding using JAXB Wizard, then overriding the created tasks. I copied <target name="jaxb-code-generation" ... from nbproject/xml_binding_build.xml to build.xml and customized the parameters of the XJC task:
<import file="nbproject/build-impl.xml"/>
<target name="ask-something">
<input message="Do you like to customize the best IDE of all times?"
validargs="Yes, Yes"
addproperty="answer"/>
<echo message="Answer Yes! ${answer}" />
</target>
<target name="jaxb-code-generation" depends="xjc-typedef-target">
<mkdir dir="build/generated/addons/jaxb" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig"/>
<mkdir dir="build/generated/jaxbCache" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig"/>
<mkdir dir="${build.classes.dir}" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig"/>
<mkdir dir="build/generated/jaxbCache/HandleSystemBinding"/>
<!-- remove catalog attribut here or change refs in catalog.xml : catalog="catalog.xml" -->
<xjc package="de.gbv.examples.handesystembinding" destdir="build/generated/jaxbCache/HandleSystemBinding">
<classpath>
<pathelement location="${src.dir}"/>
<pathelement path="${jaxbwiz.xjcrun.classpath}"/>
</classpath>
<arg value="-xmlschema"/>
<arg value="-verbose"/>
<!-- customize this -->
<schema file="web/A.xsd"/>
<depends file="web/B.xsd"/>
<!-- end customization -->
<produces dir="build/generated/jaxbCache/HandleSystemBinding"/>
</xjc>
<copy todir="build/generated/addons/jaxb">
<fileset dir="build/generated/jaxbCache/HandleSystemBinding"/>
</copy>
<javac destdir="${build.classes.dir}" srcdir="build/generated/addons/jaxb" source="${javac.source}" target="${javac.target}" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig">
<sourcepath location="${src.dir}"/>
<classpath path="${jaxbwiz.gensrc.classpath}"/>
</javac>
</target>
Note: Later discussions on netbeans issue tracking showed that there is a simpler way by first running “refresh” on the bindings schema and then doing “clean and build”. For that you don’t need to modify the ant target, nevertheless the discussed modification gives you this with just the “Regenerate” action click.
Wed 30 Jan 2008
Netbeans’ help browser doesn’t react on font size settings (User Startup Settings ). This is an old issue which you can study here . Actually all to do is to override the default CSS settings in:
netbeans-6.0/ide8/docs/org/netbeans/modules/usersguide/ide.css
Download a workaround version ide.css.
I had to edit this file to fit my needs (on KDE, ubuntu):
body {
font-size: 15pt;
font-family: Arial, Helvetica, SansSerif, sans-serif;
...
To see the changes you do not need to restart the IDE or something like that. Just go to another help page.
Netbeans 6.5
Here you the appropriate .css file is ide10/docs/org/netbeans/modules/usersguide/ide.css .
An example for a possible adaptation:
body {font-size: 15pt;
font-family: SansSerif, Arial, Helvetica, sans-serif;
margin-left: 5;
margin-right: 5;
color: Black;
background-color: White}
p {font-size: 15pt;
margin-top: 5;
margin-bottom: 5}
....
Wed 30 Jan 2008
Posted by admin under
KDE ,
ubuntuNo Comments
If it happens that you see the error message:”Unknown device: x11″ when you want a print file preview or similar, install the gs-esp-x package. That will fix the problem.
Mon 28 Jan 2008
In simple REST-style webservice situation you sometimes have to model container-item relationships and provide an XML Schema as a means for interface description.
Here is an example how to design the associated XML Schema.
Example of an XML document (container):
<ns2:container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
xmlns:ns2='http://xml.example.org/schema/container'
xsi:schemaLocation='http://xml.example.org/schema/container container.xsd'>
<ns2:item>
<ns2:value>A</ns2:value>
</ns2:item>
<ns2:item>
<ns2:value>B</ns2:value>
</ns2:item>
</ns2:container>
In REST you often want to give access to an item without the container wrapper. One solution is to provide two schema files – one for item and one for container:
container.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
targetNamespace="http://xml.example.org/schema/container_item"
xmlns:tns="http://xml.example.org/schema/container_item"
elementFormDefault="qualified">
<xsd:include schemalocation="item.xsd"/>
<xsd:element name="container">
<xsd:complextype>
<xsd:sequence>
<xsd:element ref="tns:item" maxoccurs="unbounded"/>
</xsd:sequence>
</xsd:complextype>
</xsd:element>
</xsd:schema>
item.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
targetNamespace="http://xml.example.org/schema/container_item"
xmlns:tns="http://xml.example.org/schema/container_item"
elementFormDefault="qualified">
<xsd:element name="item" type="tns:itemType">
<xsd:complextype name="itemType">
<xsd:sequence>
<xsd:element name="value" type="xsd:string"/>
</xsd:sequence>
</xsd:complextype>
</xsd:element>
</xsd:schema>
Sat 26 Jan 2008
It seems to me that there are basically two ways to get started with the examples of the Jersey distribution (see also Java Webservices – Relationship between JAX-WS, JAX-RS, Metro and Jersey) in Glassfish.
First you can use the Glassfish’s update center executing:
$path/updatecenter/bin$ ./updatetool
like described for example in Japod’s blog.
But currently only version 0.4 is available here.
The other way is : download and unzip the newest version of Jersey. In the root directory of the unzipped archive you will find an
ant script, execute it like this:
$path/jersey-0.5-ea$ ant -f jersey-on-glassfish.xml -Dgf.home=$HOME/bin/glassfish install
with appropriate gf.home property supplied.
If you get an error message similiar to this one:
BUILD FAILED
/home/kostja/Development/jersey/jersey-0.5-ea/jersey-on-glassfish.xml:103: The following error occurred while executing this line:
/home/kostja/Development/jersey/jersey-0.5-ea/jersey-on-glassfish.xml:43: /home/kostja/Development/jersey/jersey-0.5-ea/examples/GlassfishDB not found.
which means some example is missing in the distribution, edit the jersey-on-glassfish.xml file, comment out the matching lines:
<!-- copy-example example.name="GlassfishDB"/>
<update-nb-prop nb.prop.file="${gf.home}/jersey/examples/GlassfishDB/nbproject/project.properties"/ -->
Be aware! This procedures will only install the examples and won’t add auto-magically the jersey jars to Glassfish’s runtime classpath. So
you have to take care by yourself to include the jars to the build target, see the provided examples for the jars needed:
glassfish/jersey/examples/SimpleServlet/nbproject/build-impl.xml:
<target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir">
<copy file="${file.reference.activation.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copy file="${file.reference.jsr250-api.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copy file="${file.reference.persistence-api-1.0.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copy file="${file.reference.asm-3.1.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copy file="${file.reference.jsr311-api.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copy file="${file.reference.jersey.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
</target>
glassfish/jersey/examples/SimpleServlet/nbproject/project.properties:
# some of this properties are set by jersey-on-glassfish.xml
# during installation
ashome.jersey.lib.dir=../../lib
ashome.lib.dir=../../../lib
...
file.reference.jsr250-api.jar=${ashome.jersey.lib.dir}/jsr250-api.jar
...
file.reference.jersey.jar=${ashome.jersey.lib.dir}/jersey.jar
...
javac.classpath=${file.reference.servlet.jar}\:${file.reference.activation.jar}\:${file.reference.jsr250-api.jar}\:
${file.reference.persistence-api-1.0.jar}\:${file.reference.asm-3.1.jar}\:${file.reference.jsr311-api.jar}\:
${file.reference.jersey.jar}
Tue 22 Jan 2008
Posted by admin under
bash ,
shellNo Comments
Have you ever been surprised by obvious, even trivial facts which you have been overlooking for years?
Today it hit me:
I used shell metacharacters for expansion and even wrote quite complex bash scripts and used tree (not installed by default in ubuntu) to look into a given display depth of the directory tree. But a combination of ls and shell expansion can do quite the same:
ls */*
ls */*/*
Another interesting example from the same category is
echo */
to list all directories in working directory.
One more example – List only the directories :
ls -d */
works similiar to
find . -type d -maxdepth 1 -mindepth 1
Sun 20 Jan 2008
Have you ever wondered about the relationship of different actors within Java’s Webservice Stack? I did. The key to the right answers you may find watching this list of Glassfish projects.
So there seems to be a simple formula (RI = reference implementation):
JAX-WS = JAVA-API( XML-based Webservices, means mainly WSDL/SOAP though REST is possible too )
RI(JAX-WS) = { javax.xml.ws.**.* , core Web services support } = JAX-WS “RI” [is subset of] Metro
Metro = JAX-WS “RI” + WSIT/Tango ( WSIT/Tango provides support for Security, Reliability, Transactions and Interoperability with .NET 3.0 )
JAX-RS = JAVA-API( RESTful Web Services )
RI(JAX-RS) = { javax.ws.rs.**.* } = Jersey
JAX-WS 2.1 along with JAXB 2.1 is integrated in JDK 6 Update 4 release as is JAX-WS in JDK 6. It is part of Java EE 5 as well. To use Metro 1.1 on JDK6 U4, you just have to put the Metro jars in the classpath. Metro is integrated with Glassfish Application Server.
It is possible to run REST Services with JAX-WS using the appropriate Binding like described in RESTful Web Services.
JAX-RS is yet not finally released (see Schedule). If you are using NetBeans IDE 6.0, you do not need to download the Jersey distribution. Instead, install the RESTful Web Services plugin from the Plugin Manager under the Tools menu. Developing RESTful Webservices is much easier here. Implementing RESTful Web Services in Java provides a good start.
If you are looking for the Metro libraries, either get them from GlassFish (webservices*.jar) , or download them from Metro distribution.
Some nice slides for an Metro/Jersey overview : Metro and Jersey.
To use Metro in your application you will need this jars (see also Metro FAQ):
$METRO_HOME/lib/webservices-rt.jar
$METRO_HOME/lib/webservices-api.jar
$METRO_HOME/lib/webservices-extra-api.jar
$METRO_HOME/lib/webservices-extra.jar
Sun 20 Jan 2008
It seems that we finally have got this simple feature for classpath (see Bug ID: 4339262).
Now it is possible to use wildcards in classpath definition:
javac -cp libs/* -verbose -encoding UTF-8 src/mypackage/*.java -d build/classes
This is a citation from man:java (java-6-sun, linux):
-cp classpath
Specify a list of directories, JAR archives, and ZIP archives to search for class files. Class path entries are separated by colons (:). Specifying -classpath or -cp overrides any setting of the CLASSPATH environment variable.
If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the current directory (.).
As a special convenience, a class path element containing a basename of * is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR (a java program cannot tell the difference between the two invocations).
For example, if directory foo contains a.jar and b.JAR, then the class path element foo/* is expanded to a A.jar:b.JAR, except that the order of jar files is unspecified. All jar files in the specified directory, even hidden ones, are included in the list. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory. The CLASSPATH environment variable, where defined, will be similarly expanded. Any classpath wildcard expansion occurs before the Java virtual machine is started — no Java program will ever see unexpanded wildcards except by querying the environment. For example; by invoking System.getenv(“CLASSPATH”).
Fri 18 Jan 2008
Command line utilities are great for one-pointed tasks or for batch processing, but sometimes you just want to browse around and quickly play with the options. For that purpose I prefer to use GUI-tools.
In ubuntu you can use the svn-workbench as an GUI-Client written in python to subversion repositories. I am using KDE, so installing kdesvn (also see kde-apps.org) gives me a repository access and management functions right in my Konqueror file browser by using addresses like: ksvn+https://rcs.somehost.de/rep1. In this way you can work in repositories without explicit checkout. The only draw back appears in case you want to copy directories. Due to Konquerors way of copying/moving with KIO you will be asked for log messages for each single subdir or file recursively. To avoid being asked for log messages every time start kdesvn, go to Main Menu Settings – Configure Kdesvn – KIO/Commandline – check KIO operations use standard logmessage .
Kdesvn adds extra functions in Konqueror’s context menu : RightClick – Actions – Subversion . Kate and QuantaPlus Integration is also provided by kdesvn.
BTW: Subclipse is a good svn GUI client implementation as well, but requires an Eclipse installation.