I came across the same problem. My personal (and ugly!) Workaround for this is to identify the method that imports; you still have to call this function, but at least it groups the import in one place, albeit inside the lines.
function cmd = initJava() cmd = 'import package.*'; if nargout == 0 warning('off','MATLAB:Java:DuplicateClass'); evalin('caller',cmd); warning('on','MATLAB:Java:DuplicateClass'); end; end
This can be called either initJava()
or eval(initJava())
. If I remember correctly, the former does not always do what it should do, but you will have to check it yourself.
If anyone has a better / better / different solution, I am very interested to hear that.
source share