@Philipp - this is a byproduct of the builtin javaaddpath function, as you have found. It is a limitation of this function that has existed for ages and as far as I know has no known workaround. You might try to contact MathWorks to ask for this to be fixed, but don't hold your hopes too high...
I found a small problem that I can’t fix in the code.
I am using ScreenCapture in a GUI where I have defined a few global variables. All those variables are deleted when I run ScreenCapture for the first time. I traced it back to the following function 'javaaddpath' which seems to delete my global variables. It is only called for the first time I run ScreenCapture as afterwards the java file is loaded.
% Add the necessary Java class (ImageSelection) to the Java classpath
if ~exist('ImageSelection', 'class')
My workaround is to load the java class during GUI loading. But maybe there is a better way of managing this in the script? Maybe there is a problem with my Matlab version which is 7.13 at the moment. Maybe it is time to upgrade…