views:

89

answers:

1

I have a problem wit the software I'm working on.

We are accessing Windows system calls via JNA, and we have to define some Windows structure (Java class that extends the JNA Structure) to be able to access them.

The application has to work with 32-bit and 64-bit architecture, but the problem with the structures is that attributes in them change based on the system architecture (from int to long for example).

Is there an easy (and sane) way to do conditional compilation a-la #ifdef in Java using ant? Are there any other ways to achieve this kind of conditional #ifdef?

The other way we are contemplating is to create a general interface, create two different structures for 32-bit and 64-bit, and then handle the different case with some if-else.

Thanks.

+3  A: 

Would the Ant condition clauses not do

http://ant.apache.org/manual/Tasks/condition.html

UPDATE: I think I finally got what you're trying to do. Looking at the javac man here I don't think the Java compiler will let you do that, regardless of the conditions you put in Ant. Either way I found a post on stackoverflow on determining the system architecture and a thread on the sun forums that you might find helpful.

Matti
+1 got there before me. Also, use if parameter for your build target.
Adrian Regan
Hmmm, I'm not really grokking how I should use it to enable-disable parts of code in a Java file at "compile" time. I better take a look at how to use Tasks.Thanks for pointing me to that.
Milo Casagrande
I'm not familiar with what #ifdef does. Are you trying to change ints to longs in the program code depending on which architecture you are compiling for?
Matti
@maffel: yes, that is want I would like to achieve.
Milo Casagrande
@maffel: thanks for the other links, will try to take a look if they achieved something in that way. But I think I'll have to handle it with some if-elses inside the code.
Milo Casagrande
@Milo Casagrande: Yeah, the sun forum post at least gives you the tools to do that. I'm not sure though if that is the best way go about it. I mean I think it would be easier from a maintain point of view to have two separate classes, more work yes, but also a cleaner separation between the two. I suppose you would have to create a factory to go along with that in order for the other classes to have a clean interface into getting an object reference. Happy coding :)
Matti