1

About a year ago I started work on a Java project which required a native C library. I used javah to generate the header file and then wrote the library. This was all done in Windows 7.

Now I'm trying to revisit the project and add to the native library, I've modified the java, saved the project and exported creating a new jar file.

I wrote a batch file to generate the C header file, however this is the problem, it no longer works and I'm not sure why or how to resolve the error. My batch file, 'mkhdr.bat' contains:

"D:\Program Files\Java\jdk1.7.0_25\bin\javah" cantley.co.uk.clsMain

The path to javah is correct and the batch file is run from the root of the project which resides in eclipse workspace.

But when I try to run this I get:

Error: Could not find class file for 'cantley.co.uk.clsMain'.

I've tried adapting the javah call including -classpath but nothing works. The project folder contains the following:

|-.settings (eclipse settings)
|-cantley (top folder of my package)
| |-co
|    |-uk
|       |-clsMain.java (all the java files as well as class files)
|-libsr (my native library build and source files)
|-.classpath (eclipse classpath configuration xml)
|-.project (eclipse project xml)
|-flipmngr (my eclipse project configuration)
|-flipmngr.jar (my exported jar)
|-mkhdr.bat (batch file to produce native C header file)

Thank you,

greg-449
  • 109,219
  • 232
  • 102
  • 145
SPlatten
  • 5,334
  • 11
  • 57
  • 128
  • How do you run it exactly, do you run it against jar or directory, which contains classes? What are your packages definitions, is `cantley` part of your package name or just a folder, where eclipse keeps sources? Can you add `package` declaration for the class `clsMain` ? – lpiepiora Jun 01 '14 at 18:44
  • I run the batch file from the root of the project folder. The package name is: cantley.co.uk – SPlatten Jun 02 '14 at 08:07
  • And how do you define classpath ? – lpiepiora Jun 02 '14 at 08:25
  • classpath isn't set, I tried passing classpath as an option -classpath path, on javah, it didn't help. – SPlatten Jun 03 '14 at 18:31
  • Just to drill on the subject, to what exactly did you try to set `-classpath`? – lpiepiora Jun 03 '14 at 18:41
  • I tried setting it to the location of my project classes: /cantley/co/uk – SPlatten Jun 04 '14 at 12:49
  • Set your classpath to the location where your classes are generated, not to the location where the particular class exists. E.g. if your class is in `bin/cantley/co/uk`, try setting it to `bin`. If the class is in package `cantley.co.uk`, then Java will find it. – lpiepiora Jun 04 '14 at 14:49
  • Ok, trying to simplfy, I've created a very simple project.... The application only java file contains: [code]package helloworldJava; public class clsMain { // Native routine to receive data from the specified serial device private static native int openDevice(String strDevice, int intBaudRate, int intRx); private static native byte[] readDevice(int intFD, int intExpectedLength, int intDebug); public static void main(String[] args) { System.out.println("Hello World Java!"); } }[/code] – SPlatten Jun 08 '14 at 16:42
  • Please ignore last post, found this:http://stackoverflow.com/questions/9940381/how-to-generate-jni-header-file-in-eclipse – SPlatten Jun 08 '14 at 17:14
  • What am I doing wrong followed this exactly: http://stackoverflow.com/questions/9940381/how-to-generate-jni-header-file-in-eclipse but I get an error reported in the console and no header generated, Exception in thread "main" java.lang.IllegalArgumentException: Not a valid class name: /home/simon/workspace/helloworldJava/bin – SPlatten Jun 08 '14 at 17:43
  • Solved, created header with: javah -o "native.h" -classpath "/home/simon/workspace/helloworldJava/bin" helloworldJava.clsMain – SPlatten Jun 10 '14 at 18:23

0 Answers0