We're Hiring!

How to get the Java Gateway work in MATLAB?

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Re: How to get the Java Gateway work in MATLAB?

Postby Kouichi_C_Nakamura » Mon Oct 01, 2018 2:56 pm

It's one of the toolboxes which the error message mentioned. Looks like a conflict, as you have guessed. Kouichi
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: How to get the Java Gateway work in MATLAB?

Postby Kouichi_C_Nakamura » Wed Oct 31, 2018 5:50 pm

I have installed MATLAB R2017a (I also applied a security update 3) with Control System Toolbox.

Then, I tried the following, and it worked.

Code: Select all

>> [gateway,user,cred] = loadOmeroGateway(userName, password, host)

--------------------------
OMERO.matlab Toolbox
5.4.6-ice36-b87
--------------------------

gateway =

omero.gateway.Gateway@efb952c


user =

omero.gateway.model.ExperimenterData (id=1884)


cred =

omero.gateway.LoginCredentials@2ca142fc



I checked all the `connect.m` files in MATLAB search path and `control\ctrlobsolete\connect.m` was included.

Code: Select all
>> which connect -all
C:\Program Files\MATLAB\R2017a\toolbox\matlab\iofun\@ftp\private\connect.m                % Private to @ftp
connect is a Java method                                                                  % omero.gateway.Gateway method
C:\Program Files\MATLAB\R2017a\toolbox\shared\controllib\engine\@DynamicSystem\connect.m  % DynamicSystem method
C:\Program Files\MATLAB\R2017a\toolbox\control\ctrlobsolete\connect.m


Code: Select all
>> which connect
C:\Program Files\MATLAB\R2017a\toolbox\control\ctrlobsolete\connect.m


Code: Select all
>> ver
----------------------------------------------------------------------------------------------------
MATLAB Version: 9.2.0.959691 (R2017a) Update 3
MATLAB License Number: 972477
Operating System: Microsoft Windows 10 Pro Version 10.0 (Build 17134)
Java Version: Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
----------------------------------------------------------------------------------------------------
MATLAB                                                Version 9.2         (R2017a)
Control System Toolbox                                Version 10.2        (R2017a)
Curve Fitting Toolbox                                 Version 3.5.5       (R2017a)
Image Processing Toolbox                              Version 10.0        (R2017a)
NeuroSpec                                             Version 2.0                 
Parallel Computing Toolbox                            Version 6.10        (R2017a)
Signal Processing Toolbox                             Version 7.4         (R2017a)
Statistics and Machine Learning Toolbox               Version 11.1        (R2017a)
Wavelet Toolbox                                       Version 4.18        (R2017a)


For the version of `loadOmeroGateway.m` that I used, please see:
https://gist.github.com/kouichi-c-nakam ... 71a8578596
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: How to get the Java Gateway work in MATLAB?

Postby jburel » Thu Nov 01, 2018 12:04 pm

Dear Kouichi

It works because you have Bio-Formats in the path.
As soon as you remove Bio-Formats then you will have the issue with the connect function reported previously
Requiring B-F in the path so that the OMERO toolbox works using the JavaGateway is too much in my opinion.


Cheers
Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: How to get the Java Gateway work in MATLAB?

Postby Kouichi_C_Nakamura » Thu Nov 01, 2018 1:04 pm

Hi Jmarie,

Somewhere else in the forum, I was repeatedly (over and over) told that you guys are planning to make Gateway available to MATLAB. So, I suggested you a solution here.

Now, if you say this is too much, what do you think is the way forward? Abandon the possibility of using Gateway from MATLAB? Or, would you like to have code snippet from bfCheckJavaPath included in OMERO-MATLAB toolbox?

But my new issue (viewtopic.php?f=6&t=8615&p=20163#p20163) might have a deeper problem in the use of Gateway in MATLAB, unless you can find a solution. Even though you can instantiate a Gateway object, you may not able to use the getFacility method.

Well, this may be too much indeed. I might switch to Python.

Cheers,
Kouichi
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: How to get the Java Gateway work in MATLAB?

Postby jburel » Thu Nov 01, 2018 2:39 pm

Hi Kouichi

I think you misunderstood my comment,
we definitely appreciate your efforts to push the toolbox forward.
I was just concerned about the new requirement in order for it to work. In the current state of the Gateway, we do not have much choice. The sole option left is probably to add a new method to the Gateway itself e.g. connectToServer.

I did not have a chance to look at your other post. I will do that later on.

Thanks for pushing it.

Cheers

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: How to get the Java Gateway work in MATLAB?

Postby Kouichi_C_Nakamura » Thu Nov 01, 2018 3:15 pm

On the other hand, I also thought, if one is extensively using MATLAB for image processing, it's quite likely that he/she may be already using Bio-Formats MATLAB toolbox. And OMERO-MATLAB and Bio-Formats are both from OME. So, it may not be that demanding in practice.

I agree that, if a method of Gateway can offer what bfCheckJavaPath is needed now for, that would be nicer.

Best,
Kouichi
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: How to get the Java Gateway work in MATLAB?

Postby Kouichi_C_Nakamura » Fri Nov 02, 2018 3:29 pm

I just wondered why does the Gateway object require `loci/formats/meta/MetadataStore` in the first place for its methods, when the package loci/formats/... is not included in OMERO-MATLAB itself? Is this just an issue specific to MATLAB environment? Does one of the methods of Gateway really need `loci/formats/meta/MetadataStore`? I don't know where I can find the Java source code.

Can we get rid of this requirement?

If not, can we embed `loci/formats/meta/MetadataStore` to OMERO-MATLAB?

This implies that the method 'connect' of 'gateway' is not visible to MATLAB. Indeed, if I try to get the list of Java methods of the 'gateway' object, it issues a Java error, complaining that `loci/formats/meta/MetadataStore` is not found.


Code: Select all
A Java exception occurred getting the method description for the omero.gateway.Gateway class:
     Java exception occurred:
     java.lang.NoClassDefFoundError: loci/formats/meta/MetadataStore
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at com.mathworks.jmi.CustomURLClassLoader.findClass(ClassLoaderManager.java:760)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.privateGetPublicMethods(Unknown Source)
        at java.lang.Class.getMethods(Unknown Source)
        at com.mathworks.jmi.OpaqueJavaInterface.getMethodDescriptions(OpaqueJavaInterface.java:278)
     Caused by: java.lang.ClassNotFoundException: loci.formats.meta.MetadataStore
        at java.net.URLClassLoader.findClass(Unknown Source)
        at com.mathworks.jmi.CustomURLClassLoader.findClass(ClassLoaderManager.java:760)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 17 more

Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: How to get the Java Gateway work in MATLAB?

Postby jburel » Tue Nov 06, 2018 1:02 pm

Hi Kouichi

The Gateway has a method ` getImportStore` returning the `OMEROMetadataStoreClient` [1]. That class requires `loci/formats/meta/MetadataStore`
The class extends ``ome.xml.meta.MetadataStore`` which is included in the omero_clients.jar
but `loci/formats/meta/MetadataStore` does not seem to be included.
We will need to look into that

Cheers
Jmarie

[1] https://github.com/openmicroscopy/openm ... lient.java
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: How to get the Java Gateway work in MATLAB?

Postby Kouichi_C_Nakamura » Tue Nov 06, 2018 1:59 pm

Of course, I don't understand the whole picture, but if `loci.formats` is not part of omero, these dependencies do not make good sense to me. This I think is the bottom of the problem?

Code: Select all
import loci.formats.IFormatReader;
import loci.formats.ImageReader;
import loci.formats.meta.IMinMaxStore;
import loci.formats.meta.MetadataStore;


https://github.com/openmicroscopy/openm ... va#L58-L61
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: How to get the Java Gateway work in MATLAB?

Postby jburel » Wed Nov 07, 2018 9:13 am

Hi Kouichi

This is a dependency (formats-api) that is required to be able to import data using Bio-Formats
We will need to package the jar in omero_client to fix the issue
The OMERO.matlab toolbox is the only place where we use omero_clients.jar
cheers
Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Previous

Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest