I have been using Swig to create a Java wrapper for a a library written in C++. The wrappers get generated into a package and then jar
'ed. The files are compiled correctly and work perfectly with java but I can't call it from MATLAB.
I tried adding the path to the jar in the static Java path file in MATLAB and then calling the classes in the jar file but I get the error "Undefined variable or class.."
Or if I try using javaObject(...)
"No class * can be located on Java class path"
.
I'm not sure what I am doing wrong.
EDIT:
To test calling a c++ library from MATLAB, I created a simple "data reader" class which contains a function that writes a randomly generated vector< vector<double> >
to a text file and and a function that reads it.
The swig files generated are: SimpleReader.java
, DoubleVector.java
, exampleJNI.java
, example.java
, DoubleVector2.java
in the package com.example.reader
. These are compiled and packed into example.jar
(the library dll generated is also packed into the jar).
It all works fine calling it from java so the problem must be specific to MATLAB. There is not much code for MATLAB as nothing seems to work. I get as far as
javaclasspath('c:/reader/reader.jar');
obj = com.example.reader.SimpleReader;
at which point I get 'Undefined variable "com" or class "com.example.reader.SimpleReader"'