使用 Java 和 ant 进行条件编译
我正在开发的软件有问题。
我们通过 JNA 访问 Windows 系统调用,并且必须定义一些 Windows 结构(扩展 JNA 结构的 Java 类)才能访问它们。
应用程序必须使用 32 位和 64 位体系结构,但结构的问题是其中的属性会根据系统体系结构而变化(例如从 int 到 long)。
有没有一种简单(且理智)的方法可以使用 ant 在 Java 中执行条件编译 a-la #ifdef ?还有其他方法可以实现这种条件#ifdef吗?
我们正在考虑的另一种方法是创建一个通用接口,为 32 位和 64 位创建两种不同的结构,然后使用一些 if-else 处理不同的情况。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Ant 条件子句不会
http://ant.apache.org/manual/Tasks /condition.html
更新:
我想我终于明白了你想要做的事情。查看
javac
man 这里 我认为 Java 编译器不会让你这样做,无论你在 Ant 中设置什么条件。不管怎样,我在 stackoverflow 上找到了一篇关于确定的帖子系统架构和 Sun 论坛上的线程可能对您有帮助。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.wwyt 是 Java 语言的条件编译预处理器。它接受(注释掉)指令,如 #if、#else、...等。它是一个 Windows 命令行工具,可以在调用 Ant 进行构建之前用作预处理器。 (构建后,它可以将转换后的文件恢复到原始状态。)不确定这是否有帮助,只是让你知道。链接在这里:http://www.adarian.com/wwyt
wwyt is a conditional compilation pre-processor for Java language. 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. (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