Talha Talha - 1 month ago 17x
Java Question

Using MATLAB (Windows) generated Java package in Linux

As far as I know, I can run .mex files on Linux that were generated on Windows by installing Matlab Runtime on Linux (correct me if I am wrong). But what if I want to use a MATLAB generated java package, that was generated on Windows, on a Linux (like Ubuntu)?


I have to test a feature that uses audio processing. If test is successful, we will buy the products we need. At the moment I have my requested license on Windows, since the requested license have machine specific limitation, I am able to generate some test java code on my Windows machine, now the application is to be deployed on android, so I learnt from google that it needs matlab runtime to run or compiler to use converted/generated code. Android system has no MCR or simple Matlab Runtime installation support, so I moved to this solution.

Use a linux to host servlet that takes some input from android, do processing return answer in terms of json or text. Now my java package is generated using Windows machine, and I am lost.

From my knowledge this code-convert-servlet-deploy-once approach is cost effective than MATLAB Production Server, since we have to buy license once for the specific products. Remember licensing phase is after we test if this approach is giving us desired results.


  • Windows 10

  • MATLAB 2016a (Trial)

  • MATLAB products (Compiler/sdk, Signal Processing/Audio Processing Toolbox)

  • Package made using JDK 1.7.x (Exactly matching MATLAB jdk/jre version on Windows)

  • Ubuntu 16 Desktop (with Oracle jdk 8_101 installed, also MATLAB Runtime installed, I can also work with jdk 7.x (same as MATLAB used on Windows when generating package))


  • How can I use this java package in Linux when I create a java program?

  • What software + licenses are needed to make it possible?

  • Should I install MATLAB ON Linux machine, generate Java Package ON Linux machine and use that package in java program ON same linux machine? ( I think I will need to request license for it again )

  • Are there any other methods? Am I missing something?


Java packages generated by MATLAB Compiler SDK are in general cross-platform - however, they may call mex files, or other libraries, that are platform-specific, and if they do the Java package as a whole will end up being platform-specific.

You aren't entirely clear about whether you're calling mex files or not; and you may be calling platform-specific libraries without realising it (for example, Signal Processing Toolbox might call out to some library for some of its operations).

In addition, your comment about being "able to run mex files on Linux that were generated on Windows by installing the MATLAB Runtime on Linux" is confused - mex files are not cross-platform, and the don't use MATLAB Runtime at all.

So with respect to platforms - you may be able to use a Java package generated on Windows on Linux, so long as it doesn't call any Windows-specific mex files or libraries. But if you generate it on Linux, you can rule that issue out, so it will be easier for you if you use the same platform for compilation and execution. It should be fairly easy for you to reassign your MATLAB license to a Linux machine to do that.

Am I missing something?

Yes: the way you're proposing to do things is very unlikely to scale well. If you have a Java servlet on your Linux server along with a Java package generated by MATLAB Compiler SDK, then whenever you make a call to the servlet it will make a call to the Java package, which will start up the MATLAB Compiler Runtime (MCR), run your MATLAB code, return the answer to the servlet, and then shut down the MCR.

The MCR takes quite a long time to start up (nearly as long as MATLAB). So each call will take rather a long time, just due to MCR startup times.

So you can get around that by creating some sort of utility tool that will start up a an MCR and keep it there, and pass through requests and return answers to the servlet.

But then you've only got one MCR - what happens if you get multiple requests at once? They'll be queued up (or dropped) and it won't scale. So you'll need to improve your utility tool, so that it manages a pool of MCRs and passes requests through to a free one, load-balancing them as it goes.

But then what happens if an MCR crashes, or runs ouot of memory? The utility tool will need to monitor that possibility, and restart any crashed ones.

And you'll need some extra stuff that will enable you to administer all that stuff conveniently.

Once you've done all that (which will be hard), you'll realise that you have now pretty much written MATLAB Production Server. I know it's expensive, but you might like to take another look at it before committing to the solution you're considering.