简体   繁体   English

使用Java和ant进行条件编译

[英]Conditional compilation with Java and ant

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. 我们正在通过JNA访问Windows系统调用,并且必须定义一些Windows结构(扩展JNA结构的Java类)才能访问它们。

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). 该应用程序必须使用32位和64位体系结构,但是结构的问题在于结构中的属性会根据系统体系结构而变化(例如,从int到long)。

Is there an easy (and sane) way to do conditional compilation a-la #ifdef in Java using ant? 有没有一种简单(明智的方法)使用ant在Java中进行条件编译a-la #ifdef? Are there any other ways to achieve this kind of conditional #ifdef? 还有其他方法可以实现这种有条件的#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. 我们正在考虑的另一种方法是创建一个通用接口,为32位和64位创建两个不同的结构,然后使用if-else处理不同的情况。

Thanks. 谢谢。

Would the Ant condition clauses not do 蚂蚁条件条款不会

http://ant.apache.org/manual/Tasks/condition.html 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. 这里看着javac我认为无论您将Ant放在什么条件下,Java编译器都不会允许您这样做。 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. 无论哪种方式,我都在stackoverflow上找到了有关确定系统体系结构的文章,以及在sun论坛上找到的一个线程 ,可能会对您有所帮助。

wwyt is a conditional compilation pre-processor for Java language. wwyt是Java语言的条件编译预处理器。 It accepts (commented out) directives like #if, #else, .... etc. It's a Windows command line tool and can be used as a pre-processor before calling Ant to make the build. 它接受(注释掉的)#if,#else,...等指令。这是Windows命令行工具,可以在调用Ant进行构建之前用作预处理程序。 (And after the build, it can restore the converted files back to their original state.) Not sure if this helps, just so you know. (并且在构建之后,它可以将转换后的文件还原到其原始状态。)不知道这是否有帮助,只是您知道。 Link is here: http://www.adarian.com/wwyt 链接在这里: http : //www.adarian.com/wwyt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM