0

Am trying to compile MATLAB code that employs Bloomberg's APIv3 via the Datafeed toolbox. The code runs fine within MATLAB. The compiler works fine on code without Java. The javaclasspath references the API via:

DYNAMIC JAVA PATH

C:\blpv3\API\APIv3\JavaAPI\v3.7.1.1\lib\blpapi3.jar

I get several compilation errors relating to Java (stacktrace below) on compilation with :

mcc -m -R -startmsg -R -completemsg -v my_prog.m

I suppose I need to tell mcc to link to blpapi3.jar more explicitly, but how? Do I need to set up a static Java path?

Any help would be much appreciated!


Warning: A Java exception occurred getting the method description for the
java.util.Locale class:

Java exception occurred:
java.lang.NoClassDefFoundError: com/bloomberglp/blpapi/Session
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source) 
    at java.lang.Class.privateGetPublicMethods(Unknown Source) 
    at java.lang.Class.getMethods(Unknown Source)
    at com.mathworks.jmi.OpaqueJavaInterface.doesMethodExist(OpaqueJavaInterface.java:407)
Caused by: java.lang.ClassNotFoundException: com.bloomberglp.blpapi.Session
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 5 more 
IKavanagh
  • 6,089
  • 11
  • 42
  • 47
Martin
  • 1

1 Answers1

0

After some more browsing and lots of trials, I have resolved the issue. The answers are in several posts on this site already. Anyway, there are several issues...

1

It appears that

Java exception occurred: java.lang.NoClassDefFoundError

is a runtime error, not a compile error. To fix this I updated the classpath.txt in both the COMPILER AND THE MCR, located at,

$matlabroot\toolbox\local\classpath.txt

to something like this

javaclasspath

    STATIC JAVA PATH

C:\Program Files\MATLAB\R2012a\java\patch                                                       
C:\blpv3\API\APIv3\JavaAPI\v3.7.1.1\lib\blpapi3.jar       

Alternatively, the blpapi3.jar can be copied into

$matlabroot/java/jarext

alongside the other JAR files.

Also, I removed the dynamic java path, which only works for the Matlab IDE.

2

I have disabled the ADDPATH in startup.m with a clause such as

if ~isdeployed && ~ismcc addpath D:\Matlab ... end

3

Arguments to mcc must include the directories in which the source files are located, i.e.

mcc -m -I 'source_file_dir' -v top_level_function.m

4

When handling files within the code, reference relative to the $matlabroot, e.g.

if isdeployed sFile_Path = fullfile(matlabroot,'..','Input',sFile_Name); else sFile_Path = which(sFile_Name); end

5

Notice that the $matlabroot of the MCR is different from the $matlabroot of the Matlab IDE.

Martin
  • 1