Trouble compiling matlab function that calls Java

1 view (last 30 days)
I'm trying to compile some matlab code which calls one of the built in Java methods, e.g.:
function testJava()
docNode = com.mathworks.xml.XMLUtils.createDocument('root');
xmlwrite('sample.xml',docNode);
end
Compilation works fine, but when I attempt to execute the resulting file I get the following warning message:
"Warning: Unable to load Java Runtime Environment: libjvm.so: cannot open shared object file: No such file or directory
Disabling Java support"
This leads to the following error:
"Undefined variable "com" or class "com.mathworks.xml.XMLUtils.createDocument".
Error in testJava (line 2)"
Not sure if it is relevant or not, but I'm running the matlab2013a compiler on a linux-based computing core. Compiled matlab code which does not make use of java methods works just fine, as do uncompiled m-files which call java methods but are run directly through Matlab.
Thanks very much!
  1 Comment
Morteza
Morteza on 18 Aug 2015
Edited: Morteza on 18 Aug 2015
I checked your function in MATLAB2014 and it works fine.
<?xml version="1.0" encoding="utf-8"?>
<root/>
My system has the JRE/JDK also.

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 18 Aug 2015
  2 Comments
Richard Carrick
Richard Carrick on 19 Aug 2015
No, I haven't, but it is unclear to me how to do so based on the provided link. Are there equivalents to CFLAGS and CLIBS for use with Java? I'm afraid there too many steps here that I don't understand well enough to implement
Walter Roberson
Walter Roberson on 19 Aug 2015
CFLAGS and CLIBS is the mechanism to use. -L the path to the java library and -llibjvm to indicate the library name.
I do not have the compiler to be able to find the exact file to look at or the place to configure if you are using the GUI version of the compiler tool; unfortunately the documentation for those requires a current support contract to access.

Sign in to comment.


Steven Lord
Steven Lord on 19 Aug 2015
You said you compiled the code on a "linux-based computing core" -- if you try to compile the function from inside a MATLAB session, was that session started with -nojvm? If so, what happens when you started the MATLAB session in which you tried to compile that function WITHOUT the -nojvm startup flag?

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!