Search code examples
matlabjbossclasspathclassloader

How to use matlabcontrol api and jboss


thanks in advance for attention. It's the first time i am writing on this site (quite newbie :) ) I previously read question of a user asking for my same problem. Although i read a lot i could not find a solution.

Problem: I am trying to use MatlabControl jar (http://code.google.com/p/matlabcontrol/) to "call" matlab within my java code. When i try this api within a normal java application to try it (including matlabcontrol.jar in the buildpath) everything works perfectly.

My issue is to make it work on an ejb module with jboss 5 AS: i can deploy the ejb module and i can see classes of the matlabcontrol.jar (which i put in server/default/lib folder), but it is not working and is returning me the following exception:

Caused by: java.lang.NullPointerException
at java.io.File.<init>(File.java:251)
at matlabcontrol.Configuration.getSupportCodeLocation(Configuration.java:227)
at matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:278)
at matlabcontrol.RemoteMatlabProxyFactory.requestProxy(RemoteMatlabProxyFactory.java:116)
at matlabcontrol.RemoteMatlabProxyFactory.getProxy(RemoteMatlabProxyFactory.java:134)
at matlabcontrol.MatlabProxyFactory.getProxy(MatlabProxyFactory.java:81)

that lead me to the following lines:

URL url = Configuration.class.getProtectionDomain().getCodeSource().getLocation();
        File file = new File(url.toURI().getPath()).getCanonicalFile();

The very strange thing is that very very rarely, after restarting jboss and re-deploying the ejb module, the system works!.

I really don't know if i have to modify the source code of these last 2 lines (as if it is a problem of not properly getting the location of the jar code) or to set some configuration files of jBoss to set the classpath differently.

Thanks again in advance. Any help would be very appreciate.


Solution

  • The mistake was in the code to find the location of the jar at runtime. I printed the path, which ended with "!" and double slash, so I removed these chars and I was finally able to make this API work.