I am working on a java-based framework for a Home Automation System. One of the requirements for this home automation system is that developers should be able to easily extend the functionality. I thought that a great way to simplify things would be to allow developers to create a simple XML file that describes the features of their peripheral; namely the commands that it can handle and the events that it can broadcast. (Similar to the WHEN and THEN events in systems like Wig Wag: http://www.kickstarter.com/projects/wigwag/wigwag-scan-it-control-it-rule-it-share-it)
I would like to parse the XML file that the developer provides and automatically generate Java code to interface with the rest of the system, sort of like what Google does with their R.java file in the Android SDK. (I realize that this is handled by APT and not Eclipse) Some solutions I have looked at:
- Eclipse Java Emitter Templates (JET) - JET is very complicated to use and the documentation is very poor/nonexistant. I got it to produce a Java Implementation file with a
generate()
method, but I cannot find out how to get the IDE to generate the Java code I defined in the template. I tried this tutorial: https://weblogs.java.net/blog/survivant/archive/2009/01/template_code_g.html but I could not get the Car example to work; I get this error:
Errors occurred during the build.
Errors running builder 'JET Builder' on project 'JETTest'.
Bad directive in 'main.jet' at line 1 column 1
Bad directive in 'main.jet' at line 1 column 1
Bad directive in 'main.jet' at line 1 column 1
Bad directive in 'main.jet' at line 1 column 1
- JAXB - This appears to be more for marshalling/unmarshalling Java objects, and does not solve my problem
- ANT Compiler - I got this to generate a class, but it is not quite as flexible I want (e.g. I want to be able to get the package name from the developer-defined XML, but the output directory is statically assigned in the ANT
build.xml
file.) - Apache Velocity - glanced at it but I was already frustrated about JET and it did not appear to be a great solution upon cursory inspection. (I'd be happy to be proven wrong :))
The ANT solution is so far looking best to me because it actually works, but I like JET because it seems to work the smoothest.
Now my question. Should I just go with ANT, or is JET that much better? Furthermore, if JET is that much better, can somebody PLEASE point out a simple tutorial that is not completely out of date?