Thursday, June 7, 2012

Generate XmlRootElement for jaxb objects

I recently had to add XmlRootElement to a class. After using google for a while, I finally figured out a way to do it. I Updated the pom jaxb plugin to include the annotate plugin and created a mappings file that customizes the jaxb object. pom.xml:
<plugin>
    <groupid>org.jvnet.jaxb2.maven2</groupid>
    <artifactid>maven-jaxb2-plugin</artifactid>
    <configuration>
        <extension>true</extension>
        <strict>false</strict>
        <plugins>
            <plugin>
                <groupid>org/jvnet/jaxb2_commons</groupid>
                <artifactid>annotate</artifactid>
                <version>0.4.1.5</version>
            </plugin>
        </plugins>
    </configuration>
    <executions>
        <execution>
            <id>generate</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <bindingincludes>
                    <include>*.xjb</include>
                </bindingincludes>
                <args>
                    <arg>-Xannotate</arg>
                </args>            
            </configuration>
        </execution>
    </executions>
</plugin>
file.xjb:
<!--?xml version="1.0" encoding="UTF-8" standalone="yes"?-->
<jaxb:bindings version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionbindingprefixes="annox">
    <jaxb:bindings schemalocation="filename.xsd" node="/xs:schema">
        <jaxb:bindings node="xs:complexType[@name='ObjectType']">
            <annox:annotate>
                <annox:annotate 
                annox:class="javax.xml.bind.annotation.XmlRootElement"
                name="access">
            </annox:annotate>
        </annox:annotate></jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

Wednesday, May 30, 2012

inotifywait - run scripts on file changes

When working on a project in Java, I often need to stop/start maven whenever I make changes to the source code. I wanted to have maven restart automatically whenever I changed the source code. I ended up using some bash scripts to get the job done. inotifywait will run the script restart.sh whenever a file inside src is saved. This could also be done to automatically run test when source code changes. watch.sh:
#!/bin/bash
while inotifywait -re close_write src; do ./restart.sh; done
restart.sh:
#!/bin/bash
./kill_tomcat.sh
sleep 1
mvn tomcat:run -o &
kill_tomcat.sh:
#!/bin/bash
pkill -kill -f tomcat:run

Tuesday, February 28, 2012

python rfoo rconsole

I ran accross this today. rfoo allows connecting to a remote running session of python and inspect the session's values, modify the data, etc. You can read more about it here Install in ubuntu:
sudo apt-get install python-dev
pip install cython
pip install rfoo
rconsole is a remote Python console with auto completion, which can be used to inspect and modify the namespace of a running script. To invoke in a script do:
from rfoo.utils import rconsole
rconsole.spawn_server()
To attach from a shell do:
rconsole

Saturday, October 15, 2011

wmii ubuntu 11.10 (Oneiric Ocelot)

The default gcc compiler now requires linked libraries to appear after the source file
gcc example.cpp -lsomelibrary
wmii build files have the shared libraries located before the source files, and thus can not be easily built with the default configuration.
To build wmii I updated the config.mk to use gcc-4.4 for the compiler
CC = gcc-4.4 -c
LD = gcc-4.4
This allowed the project to compiled with the following command:
dpkg-buildpackage -rfakeroot -us -uc -b

Thursday, September 29, 2011

Fix clang errors in ubuntu

In natty clang needs some the headers that are not included in ubuntu. To get clang to work use the following:
sudo ln -s /usr/include/c++/4.5 /usr/include/c++/4.4

Wednesday, September 14, 2011

When debugging in python, I use ipython's ipdb debugger to set breakpoints. I can add the following code in the location I want to stop:
import ipdb; ipdb.set_trace()
I wanted something similar for ruby. I got the same behaviour set up with the following code and patching using irb_completion's output. Install the required gem files:
gem install ruby-debug-base
gem install ruby-debug
gem install wirble
gem install patch_irb_completion;patch_irb_completion
Modify the ruby file to be debugged:
require 'rubygems'
require 'ruby-debug'
require 'wirble'
Wirble.init
Wirble.colorize

debugger #location to stop
running the code with the --debug option will stop at the requested location and drop an rdb prompt with tab completion. Reference: http://stackoverflow.com/questions/2504515/what-do-i-put-in-my-ruby-jruby-code-to-break-into-the-debugger http://www.unboxedconsulting.com/blog/irc-completion-from-the-debugger

Sunday, July 10, 2011

SpringSource Tool Suite 2.7.0.M2 Released

Eclipse 3.7 (Indigo) has been released.
From the eclipse website install the Java EE version and follow the directions found at this website link to install the SpringSource support.