1

I want to add some #define of #ifdef in eclipse for java.So that I can disable or enable some code while building for some specific target.

I have used this for C++ before but I don't know is there is way to do in java eclipse project.

please let me know if it possible or not in eclipse.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
pjain168
  • 77
  • 4
  • "So that I can disable or enable some code while building for some specific target." What kind of target? API target or processor target? – weston Nov 13 '14 at 14:07

2 Answers2

2

No, Java has no preprocessor, and this is exactly because the scenario you describe should not occur in Java.

One of Java's original main design ideas (if not the original design idea) was coined "Write once, run everywhere". This means you don't compile different bytecode for different platforms. Instead, there's only one bytecode applied on every platform.

Thus, there's no need for preprocessor instructions, because this scenario should not be necessary. If you feel you need different code on different platforms, there are ways to achieve this, but not through preprocessor macros. Maybe you could be more specific on your issue, then we can propose a suitable solution in Java.

Ray
  • 3,084
  • 2
  • 19
  • 27
0

no, java does not support preprocessor macros. What you can do is to have a java.pre file, and use ant to generate the .java files that will be compiled.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • I was using the preprocessor macro for ANT configured project but now I am using eclipse. I think eclipse also uses ant behind the scene so is it possible to configure the same in eclipse. – pjain168 Nov 13 '14 at 14:01
  • Yes you are right, eclipse uses ant, though I am not sure if the ide is configurable to do this pre-processing step. To be honest I was using `vim` at the time – Blackbelt Nov 13 '14 at 14:04