How can I force a .jar onto a worker's Java class path in MCR?
7 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Varun Bhaskar
2015-8-10
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;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!