0

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?

Community
  • 1
  • 1
Thunderforge
  • 19,637
  • 18
  • 83
  • 130

1 Answers1

1

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.

martinez314
  • 12,162
  • 5
  • 36
  • 63
  • The structure of my project is as you say. Is the creation of a build folder a necessary step or could it be somewhere else? Is it best practice to include one even if it isn't necessary? Also, does this mean that creating a Build.xml file via the "Export" command not the recommended way? – Thunderforge Apr 03 '13 at 20:31
  • @Thunderforge Yes, you need to create the folder, either manually or via Ant `` task. Eclipse won't create this folder for you automatically. If your project will build JARs or WARs or other build products (e.g. the .h file), then yes it is good practice to create this folder. (Just don't forget to, like bin, exclude it from version control.) You can use the Export function if you want, but it may add a lot of stuff you don't need. It just depends on how much you want Eclipse to do versus how much you want your script to do. – martinez314 Apr 03 '13 at 20:41
  • @Thunderforge Is the build folder in the project necessary? No, you can make it outside of the project. It can be anywhere. – martinez314 Apr 03 '13 at 20:41