Thunderforge
Thunderforge

Reputation: 20585

Javah Command in Eclipse Ant Build Script

I'm following this tutorial about creating JNI files for Mac OS X. The tutorial is written for NetBeans, but I'm trying to follow it with Eclipse. Unfortunately, this has caused me to be stuck at step 4.1.3, which is about generating a .h file using ant:

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>

First off, it seems that Eclipse projects don't include a build.xml file by default, so I used these instructions to generate one. Then I added the command as shown above. But when I build with the ant script, the .h file does not get built. No error message related to this is generated.

I believe that the reason is because Eclipse projects do not have a "./build" folder as shown in the examples, but I don't know what to put in its place. Could anybody please let me know how to fix this issue?

Upvotes: 0

Views: 1719

Answers (1)

martinez314
martinez314

Reputation: 12332

First, let's assume your Eclipse project folder structure is like this:

src/ (source files)
bin/ (compiled class files)

The above folders should be configured in your Java Build Path (see Project > Properties). The below folder and file you will need to create yourself (just right-click > New...).

build/ (build products)
build.xml  (build script)

Inside each of bin and src folders, you should have a sub-directory structure like:

ca
|--weblite
      |--jniexample

There should be a source file at src/ca/weblite/jniexample/NSSavePanel.java. And there should be a compiled class file at bin/ca/weblite/jniexample/NSSavePanel.class.

Your build.xml file should look like this:

<project name="Build" default="-post-compile">
  <target name="-post-compile">
    <javah destdir="./build" force="yes" class="ca.weblite.jniexample.NSSavePanel" classpath="./bin" />
  </target>
</project>

After executing your build script, you should see a file at build/ca_weblite_jniexampe_NSSavePanel.h.

Upvotes: 1

Related Questions