OMERO Client Library
Starting to work with the OMERO server is fairly simple from a Java client. Most important is setting up the proper classpath.
Minimum libraries
The client/ directory is available in the binary distribution or can be created from source via java omero build-default. ("<VERSION>" below represent the current value of the particular jar under dist/client).
- OMERO code
- client/client-<VERSION>.jar
- client/common-<VERSION>.jar
- client/model-psql-<VERSION>.jar
- Hibernate annotation dependencies (used by model classes)
- client/hibernate-annotations-<VERSION>.jar
- client/hibernate-search-<VERSION>.jar
- JBoss dependencies
- client/jboss-annotations-ejb3-<VERSION>.jar
- client/jboss-ejb3-<VERSION>.jar
- client/jboss-ejb3x-<VERSION>.jar
- client/jbossall-client-<VERSION>.jar
- client/jbosssx-<VERSION>.jar
- client/persistence-api-<VERSION>.jar
- Other
- client/spring-<VERSION>.jar
- client/log4j-<VERSION>.jar
- client/commons-logging-<VERSION>.jar
If you'd like to see the current values for these jars, go to: http://hudson.openmicroscopy.org.uk/job/OMERO/ws/trunk/dist/client/
Using property files
It is often desirable to not hard-code the user name and password nor the server and/or port. In that case, the empty ServiceFactory() constructor can look for properties in several well known locations. Specifically:
- classpath:omero.properties
- classpath:hibernate.properties
- classpath:local.properties
- classpath:jndi.properties
See the OMERO_HOME/etc directory for information on just what properties can be set.
Simple Jython Script : Login, Server, and ServiceFactory
For brevity's sake, a simple example in Jython rather than Java. (One could even also use the Jython console for directly interacting with the server.)
Assuming CLASSPATH has been properly set:
from ome.system import * from ome.parameters import * login = Login("name","password") server = Server("http://myhost") factory = ServiceFactory( login, server ) id = factory.getAdminService().getCurrentUser().getId() params = Parameters().addId(id) myImages = factory.getQueryService().findAllByQuery("select i from Image i where i.details.owner.id = :id",params)
For a Java example, see examples/ExampleOne.
Understanding what's going on
Obviously a lot is going on under the hood.
Hashtable env = new Hashtable(); // set properties from Login and Server Context ctx = new InitialContext(env); return (IQuery) ctx.lookup(IQuery.class.getName());
...makes calls on the server. In the case of a stateful services, the proxy returned must be held on to for all stateful calls.
Using CLASSPATH.sh from a source build
The build system also provides a bash script (OMERO_HOME/components/<component>/target/generated/resources/Classpath.sh) which will properly set your CLASSPATH environment variable upon being sourced. With CLASSPATH set, it is possible to create simple Java files
vi Test.java javac -cp $CLASSPATH:. Test.java java -cp $CLASSPATH:. Test
See also: OmeroDevelopment, OmeroContributing, OmeroCommunity, examples/ExampleOne

