我试图在spmd中使用来自第三方Java库的类,但我不断收到与导入它相关的各种错误。
下面是一个非常简单的例子:
spmd (1)
javaaddpath([pwd 'lib/guava-10.0.1.jar']);
import com.google.common.collect.MinMaxPriorityQueue;
pq = MinMaxPriorityQueue.create();
end这给了我一个错误
??? Error: MATLAB cannot determine whether "MinMaxPriorityQueue" refers to a
function or variable.
See <a href="matlab: helpview([docroot
'/toolbox/distcomp/distcomp_ug.map'],'SPMD_LIMITATIONS')">SPMD in MATLAB,
"Limitations"</a>.(当然,that "Limitations" document似乎没有什么特别相关的东西。)
将javaaddpath和/或import移出spmd块是没有帮助的;不使用import就可以这样做,而只是说pq = com.google.common.collect.MinMaxPriorityQueue.create会导致返回关于com的相同错误。
调用在spmd块外部定义的匿名函数会产生不同的错误:
javaaddpath([pwd '/lib/guava-10.0.1.jar']);
make_pq = @() com.google.common.collect.MinMaxPriorityQueue.create();
spmd (1)
javaaddpath([pwd '/lib/guava-10.0.1.jar']);
pq = make_pq();
end让我明白了
The class "com.google.common.collect.MinMaxPriorityQueue" is undefined.
Perhaps Java is not running.但Java确实在运行,因为
spmd (1)
pq = java.util.PriorityQueue();
end和
spmd (1)
javaaddpath([pwd '/lib']);
pq = ArrayPriorityComparator.create();
endwork (ArrayPriorityComparator是./lib中的一个独立java类)。
在我看来,这就像是Matlab对spmd块的解析出现了问题。但是我不认为我可以使用javaObject()或javaMethod()来解决这个问题,因为我必须调用一个静态方法来创建对象,而且我不能因为得到一个Transparency violation error就在eval中抛出它(或者,如果我把它放在一个在spmd外部定义的匿名函数中,我会得到同样的class is undefined错误)。
有什么想法吗?无论是真正的解决方案还是可怕的黑客攻击都是受欢迎的。
发布于 2011-12-01 04:17:20
我猜这是另一个“动态类路径”问题。有关如何使用“静态类路径”,请参阅Bringing Java Classes and Methods into MATLAB Workspace。
在不依赖静态类路径的情况下,可以使用下面的文章中描述的方法。
发布于 2011-12-01 04:14:51
你有没有尝试过使用pctRunOnAll来设置java路径?
恐怕我没有一个方便的集群来测试它是否可以工作。
https://stackoverflow.com/questions/8331487
复制相似问题