change default package in a JNI class

B

Bura Tino

Hi,

I'm using a java class (JMatlink) which gives access to Matlab
functionality. All of the code (1 .java and 1 .c files) for the package is
available. The problem is that the developer of JMatlink put the class in
the default package which no longer works with the newer compilers. The
original developer seems to have moved on to bigger and better things
(re-writing Matlab in Java!) and doesn't intend to fix this issue.

To someone who knows almost nothing about JNI (and about C development under
windows), what are the things that I need to do move this class into a x.y.z
package?

Many thanks in advance!

Bura
 
G

Gordon Beaton

I'm using a java class (JMatlink) which gives access to Matlab
functionality. All of the code (1 .java and 1 .c files) for the
package is available. The problem is that the developer of JMatlink
put the class in the default package which no longer works with the
newer compilers. The original developer seems to have moved on to
bigger and better things (re-writing Matlab in Java!) and doesn't
intend to fix this issue.

To someone who knows almost nothing about JNI (and about C
development under windows), what are the things that I need to do
move this class into a x.y.z package?

Since you've got the source it shouldn't be too difficult, these are
the basic steps:

- Add the package declarations to the Java files and recompile. See
this page for details about directory layout and such:
http://www.yoda.arachsys.com/java/packages.html

- Run javah on the classes that use native methods. Make sure you
specify the fully qualified classnames when you do this. Make sure
you don't have the old "packageless" classfiles in sight.

- The resulting header files will now have different (longer) names so
you need to either change the corresponding include statements in
the C source, or tell javah the short filenames you want it to
generate.

- Go through the C source and change the native method signatures to
match those generated by javah. Basically that means adding a
package prefix to each of the methods. A macro might come in handy,
depending on the number of methods.

- If there are calls to FindClass() in the C source, make sure they
all specify fully qualified class names.

- Recompile the C source.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top