GridPulse

as stimulating as black coffee and just as hard to sleep after.

Archive for October, 2007

Generating your model from a schema definition using Maven and JAXB

leave a comment

If your project requires quite a large data model and it so happens that you have a xml schema definition on hand, you can easily transform that XSD into Java classes using Maven 2, JAXB and some manual labor.

Things you might want to know:
* doesn’t work out of the box on JSE6. It actually needs a lot of work, so avoid using for now;
* you need a maven project
* you actually need a valid XSD :)

The classes are generated by JAXB xjc. You can do this by hand, but using maven and maven-jaxb2-plugin makes it a breeze.

So, this is what you must do:
* Place your schema definition in your src/main/resources directory
* Open you pom.xml and add the following(no worries, you will remove them later):


<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Maven 2 Repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>maven-repository.dev.java.net</id>
<name>Java.net Maven 1 Repository (legacy)</name>
<url>http://download.java.net/maven/1</url>
<layout>legacy</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Maven 2 Repository</name>
<url>http://download.java.net/maven/2</url>
</pluginRepository>
<pluginRepository>
<id>maven-repository.dev.java.net</id>
<name>Java.net Maven 1 Repository (legacy)</name>
<url>http://download.java.net/maven/1</url>
<layout>legacy</layout>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>

* In your build section configure the jaxb2 plugin:

<plugin>
<groupid>org.jvnet.jaxb2.maven2</groupid>
<artifactid>maven-jaxb2-plugin</artifactid>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<includeschema>**/*.xsd</includeschema>
<generatepackage>com.gridpulse.project.model</generatepackage>
</configuration>
</plugin>

As you can see, you have 2 configuration settings:
* includeSchema - schema file mask to include
* generatePackage - the package that you would like to hold the classes

After setting this up, just fire up a mvn install. This will produce the model classes in the target/generated-sources/xjc/ directory.
You can now copy them to your src directory and clean them up.
Remember to remove the JAXB2 settings from your pom.

Written by Bogdan

October 28th, 2007 at 10:21 am

Posted in Development,Java

When compiling time does matter

leave a comment

I was compiling a project, looking at my console window, just thinking that the build usually takes too long when I realised how much time I really loose while building.

I was staring at the screen, and then the Maven buildNumber for the parent pom pops up. It’s 384.

I wait for the build to finish. It took 8 minutes 47 seconds, the average build time taking about 8 minutes.

Doing the math I realise that in the last four months, working on this project, I spent a total of 384 / 60  8 hour man days looking at a black screen waiting for the build to finally end.

That could have been 6.4 extra man days for improving the product.

Written by Bogdan

October 26th, 2007 at 7:44 pm

Posted in Development

Open source car

leave a comment

After reading about the open source beer and the open source Cola, I am really surprised (in a pleasant way) to find out that an open source car has been developed that has 0 emissions, using a hydrogen hybrid engine.

I hope that all humanity (including the resource hungry corporations) will soon see the need for this kind of transportation.

Written by Bogdan

October 18th, 2007 at 10:15 am

Posted in Open Source

JiBX, Maven JiBX plugin, using collections with flexible settings

leave a comment

Before JiBX 1.1.5, names on collections were optional. That changed :)

Now, although the docs say that the name attribute is optional on collections, it’s actually required in the real world.

Some flexible setups, like mine, get really confused if the name attribute is specified, and, because it is required I can’t even bind it without setting validate to false, and if I set validate to false, the JiBX_MungeAdapter appears in my module root (${basedir}) instead of the required package.

The only solution I found for this problem is to downgrade to JiBX 1.1.3 and maven-jibx-plugin 1.1.3. I know it isn’t a real solution but what can I say, half a day is too long to loose working on something that can be fixed by a minor-version downgrade.

Written by Bogdan

October 17th, 2007 at 2:04 pm

Posted in Development,Java

A new day, still importing tablespaces

one comment

Just realised that it’s a new day. 2 AM, and 16 hours since I left home. Another one of those days.

As a techie this happens really often, sometimes I like it, other times I just hate it. I’m going to have to explain this to my girlfriend again :) .

I’m importing tablespaces, and it has to be over until 6 AM, as it’s a production application and if it’s not online and fully functional I’m going to get a lot of messages from a couple of thousand of users.

Lot’s to think about while waiting, and a lot of coffee to drink.

I wish to thank the guys that designed the oracle imp utility, which keeps on fighting on the remote datacenter, although the power in the office went down twice in the last two hours, taking my shell with it.

Top‘s top:

top - 04:09:14 up 50 days, 14:11,  3 users,
load average: 2.52, 2.44, 2.37

Tasks: 156 total,   2 running, 154 sleeping,   0 stopped
Cpu0  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa
Cpu1  : 76.2%us, 23.8%sy,  0.0%ni,  0.0%id,  0.0%wa
Cpu2  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa
Cpu3  :  0.0%us,  1.0%sy,  0.0%ni,  1.0%id, 98.0%wa
Mem:   6056016k total,  6037232k used,
18784k free,    86944k buffers
Swap:  6144852k total,   117564k used,
6027288k free,  5157960k cached

Only 4 Gigabytes left, with a little luck I’ll be done by 4 AM.

Written by Bogdan

October 15th, 2007 at 11:05 pm

Posted in RDBMS