我正在关注this tutorial关于为 Mac OS X 创建 JNI 文件。该教程是为 NetBeans 编写的,但我正在尝试使用 Eclipse 来遵循它。不幸的是,这导致我陷入了步骤 4.1.3,即使用 ant 生成 .h 文件:
Modify the build.xml file of your Netbeans project by adding the following before the closing tag:
<target name="-post-compile">
<javah
destdir="./build"
force="yes"
class="ca.weblite.jniexample.NSSavePanel"
classpath="./build/classes"
/> </target>
首先,Eclipse 项目默认情况下似乎不包含 build.xml 文件,因此我使用了 these instructions生成一个。然后我添加了如上所示的命令。但是当我使用 ant 脚本构建时,.h 文件不会被构建。不会生成与此相关的错误消息。
我相信原因是因为 Eclipse 项目没有“./build”文件夹,如示例中所示,但我不知道该放什么来代替它。有人可以告诉我如何解决这个问题吗?
最佳答案
首先,我们假设您的 Eclipse 项目文件夹结构如下:
src/ (source files)
bin/ (compiled class files)
应在 Java 构建路径中配置上述文件夹(请参阅项目 > 属性)。您需要自己创建以下文件夹和文件(只需右键单击>新建...)。
build/ (build products)
build.xml (build script)
在每个 bin
和 src
文件夹中,您应该有一个子目录结构,如下所示:
ca
|--weblite
|--jniexample
应该有一个源文件位于 src/ca/weblite/jniexample/NSSavePanel.java。 bin/ca/weblite/jniexample/NSSavePanel.class 应该有一个编译好的类文件。
您的 build.xml 文件应如下所示:
<project name="Build" default="-post-compile">
<target name="-post-compile">
<javah destdir="./build" force="yes" class="ca.weblite.jniexample.NSSavePanel" classpath="./bin" />
</target>
</project>
执行构建脚本后,您应该在 build/ca_weblite_jniexampe_NSSavePanel.h 中看到一个文件。
关于Eclipse Ant 构建脚本中的 Javah 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15777100/