0

As I specified in title how can I write Java code, what is portable in multiple environments. I currently work at large application what was very library dependent, now after some work I come with a solution to refactor that code using MVC in mind. For each method that calls another method from that specific java library, I want somehow to add (C\C++) macros. I understand that it is not possible in java because it is compiled at runtime.

For example:

#if(LIB=TMERR)
    // Activate this code region
    // Some java code here
#else if(LIB=ZPAR)
    // Activate this code region
    // Some java code here

My question is, if exist a solutions to exclude regions of code from java code without having syntax errors. Or the case would be to exclude these files from build, and using reflection methods for each function that call another methods from specific library TMERR or ZPAR.

Thanks

LXSoft
  • 587
  • 5
  • 25
  • 1
    I think you have to design your code with inheritance and interfaces to change behaviour at runtime. For something you could use properties configuration files. To have a more suitable answer you should produce an effective example and ask what you would like to achieve. – Mario Santini Nov 17 '16 at 13:53
  • Solution in post "Java conditional compilation: how to prevent code chunks from being compiled?", answered by Gareth Davis, works, but our application code has about 200k lines and at least 500 different library function calls which are pretty complex (some methods have no equivalent on the other library), adopting that implementation would be insane. – LXSoft Nov 17 '16 at 14:04
  • This is the best way to do it in Java, and also the cleanest IMO. – JnRouvignac Nov 17 '16 at 15:39
  • It separates concerns and pushes specific library code into separate classes. – JnRouvignac Nov 17 '16 at 19:50
  • Thank you, the conclusion is that it is a lot of workload, but it is the cleanest solution! – LXSoft Nov 22 '16 at 08:19

0 Answers0