views:

111

answers:

1

I have J2ME code, which I want to be able to compile using the J2ME Polish preprocessor or the wtkpreprocessor (antenna). They mostly use the same directives so it usually works, but ...

When I want to insert an URL value in the Java code this gives a problem. In Antenna the code would look like this:

//#ifdef my.url
    //# System.out.println("My Url");
    //#expand String location = "%my.url%";
//#else
    System.out.println("Default");
    String location = "http://www.some.default.url.com";
//#endif

and in J2ME Polish it would look like this:

//#ifdef my.url:defined
    //# System.out.println("My Url");
    //#= String location = "${my.url}";
//#else
    System.out.println("Default");
    String location = "http://www.some.default.url.com";
//#endif

I want some way in which I can use the preprocessors interchangeably and still be able to set the url in the build.xml, any ideas?

A: 

Perhaps you could nest the J2MEPolish directive with something that tests for one of the J2ME Polish standard variables, like polish.OS, which presumably would not be defined when using antenna.

Maybe:

//#if polish.OS:defined && my.url:defined
    //# System.out.println("My Url, J2MEP");
    //#= String location = "${my.url}";
//#elif my.url
    //# System.out.println("My Url, Antenna");
    //#expand String location = "%my.url%";
//#else
    System.out.println("Default");
    String location = "http://www.some.default.url.com";
//#endif

Antenna will evaluate the my.url:defined as false, so you might not even need to look at Polish.OS.

Perhaps you should just go with one preprocessor though - it could get messy if taken too far.

martin clayton
I have tried something similar, but unfortunately antenna still looks at the //#=, which it does not understand and gives an error.
walter