How can I force a .jar onto a worker's Java class path in MCR?

2 views (last 30 days)
To preface this question, I acknowledge that the way everything is currently coded is bad, but in this case I am a user and not a developer -- I can't just rewrite the project correctly and recompile.
The situation I'm facing is that I'm trying to run some code in MCR that opens up a parcluster and uses parfor to run a function in parallel. That function calls a custom Java package which I have added to the MCR classpath, but when workers are spawned they do not get the same classpath. I don't care how it gets done (e.g. I am comfortable modifying the default installation), but somehow I need to shove a .jar into the classpath that workers see without changing any code.
Here is the error:
No class {com.etc.etc} can be located on the Java class path
Error in {functionName}>(parfor body) (line 17)
Error in {functionName}(line 15)
Caused by:
Error using javaObject
No class {com.etc.etc} can be located on the Java class path
The package is definitely working correctly for the purposes of the MCR classpath because the code would not even get that far otherwise (a class in the same package is used before the matlabpool is spawned).
This is running on Java 6 and MCR 8.1.

Answers (1)

Varun Bhaskar
Varun Bhaskar on 10 Aug 2015
Hello,
I understand that you want each worker to dynamically load a .jar file. You can do the same by including the .jar file as an attachment to be sent to each worker when 'parpool' is started in the following manner:
parpool('AttachedFiles',{'ABC.jar'});
Each worker can then call the 'javaaddpath' to retrieve the .jar file from the attachment folder. The attachment folder can be obtained in the following manner:
folder = getAttachedFilesFolder;
  1 Comment
Alex
Alex on 10 Aug 2015
The code is already compiled and I cannot recompile. Consider the question "how do I trick MCR into including a custom .jar everywhere" as opposed to "how do I code this properly."

Sign in to comment.

Categories

Find more on Parallel Computing Fundamentals in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!