How to set up Java development environment for Zimbra Client

Greg Solovyev
3 min readJun 17, 2018

--

A couple of weeks ago I decided to move my Zimbra to GMail calendar sync app from NodeJS to Java, so that I can use Zimbra’s official client library (https://github.com/Zimbra/zm-mailbox/tree/develop/client). Before, I was using my own NodeJS library that I wrote a while ago (https://www.npmjs.com/package/zimbra-client).

This should not be so hard…

I don’t know if anyone outside of Zimbra engineering and dev contractors hired by Zimbra is using zm-client Java library, but I doubt it, because it surely isn’t at all obvious how to set it up if you want to just use the client library in your project. Anyway… here is how I got it to work.

Zimbra libraries are not on Maven Central

I don’t know why Zimbra has not put client libraries into Maven Central. Maybe, because they still have some patched dependencies that aren’t on Maven either. In either case, you cannot simply add Zimbra java dependencies to your maven or ivy module, you have to build them, publish them to your local repo and then you can use them.

Building Zimbra client library

Step 1: Clone zm-mailbox, zm-zcs and zimbra-package-stub repos

Clone the repos from Zimbra’s official GitHub: https://github.com/Zimbra/ and checkout the latest released tag (e.g. 8.8.8) or the tag that corresponds to the version of Zimbra which you are planning to work with. It might be better to do a shallow clone of just the needed tag, because the repo is rather large.

Step 2: copy jni_md.h to JDK include folder

Zimbra Native module won’t compile unless jni_md.h is in the same folder as jni.h and on Mac these files are in separate paths, so (with JDK8):

$: sudo cp /Library/Java//JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/include/darwin/jni_md.h /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/include/

Step 3: build it

  1. Download and install Apache Ant
  2. Set ANT_OPTS environment variable

$: export ANT_OPTS=”-Ddev.home=$HOME -Dzimbra.buildinfo.version=8.8.8_GA"

3. create ~/.zcs-deps and ~/.ivy2/cache folders

$: mkdir $HOME/.zcs-deps

$: mkdir -p $HOME/.ivy2/cache

4. Build the libraries

$: cd zm-mailbox

$: ant all

Step 4. Publish to local Maven repo

If you plan to use Ivy to manage your project’s dependencies, you don’t need to do that, you can just copy Ivy settings from zm-mailbox/build-ivysettings.xml and copy Ivy dependencies from zm-mailbox/store/ivy.xml. If you want to use Maven, you’ll have to publish the jars to your local Maven repo. Note, that each jar file will have the same git hash after version in the file name.

mvn install:install-file -Dfile=common/build/zm-common-8.8.8.1517810732.jar -DgroupId=zimbra -DartifactId=zm-common -Dversion=8.8.0 -Dpackaging=jar

mvn install:install-file -Dfile=client/build/zm-client-8.8.8.1517810732.jar -DgroupId=zimbra -DartifactId=zm-client -Dversion=8.8.0 -Dpackaging=jar

mvn install:install-file -Dfile=soap/build/zm-soap-8.8.8.1517810732.jar -DgroupId=zimbra -DartifactId=zm-soap -Dversion=8.8.8 -Dpackaging=jar

mvn install:install-file -Dfile=store/build/zm-native-8.8.8.1517810732.jar -DgroupId=zimbra -DartifactId=zm-native -Dversion=8.8.8 -Dpackaging=jar

mvn install:install-file -Dfile=$HOME/.ivy2/cache/ical4j/ical4j/jars/ical4j-0.9.16-patched.jar -DgroupId=ical4j -DartifactId=ical4j -Dversion=0.9.16-patched -Dpackaging=jar

Step 5: add dependencies to your project

I ended up adding the following dependencies to my pom.xml in order to get zm-client working alongside AWS and Google Java SDKs.

<! — Zimbra →

<dependency>

<groupId>zimbra</groupId>

<artifactId>zm-native</artifactId>

<version>8.8.8</version>

</dependency>

<dependency>

<groupId>zimbra</groupId>

<artifactId>zm-common</artifactId>

<version>8.8.8</version>

</dependency>

<dependency>

<groupId>zimbra</groupId>

<artifactId>zm-client</artifactId>

<version>8.8.8</version>

</dependency>

<dependency>

<groupId>zimbra</groupId>

<artifactId>zm-soap</artifactId>

<version>8.8.8</version>

</dependency>

<dependency>

<groupId>commons-httpclient</groupId>

<artifactId>commons-httpclient</artifactId>

<version>3.1</version>

</dependency>

<dependency>

<groupId>dom4j</groupId>

<artifactId>dom4j</artifactId>

<version>1.5.2</version>

</dependency>

<dependency>

<groupId>com.sun.mail</groupId>

<artifactId>javax.mail</artifactId>

<version>1.4.5</version>

</dependency>

<dependency>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

<version>1.2.17</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpclient</artifactId>

<version>4.5.2</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpasyncclient</artifactId>

<version>4.1.3</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpcore</artifactId>

<version>4.4.9</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpcore-nio</artifactId>

<version>4.4.9</version>

</dependency>

<dependency>

<groupId>xerces</groupId>

<artifactId>xmlParserAPIs</artifactId>

<version>2.6.2</version>

</dependency>

<dependency>

<groupId>xerces</groupId>

<artifactId>xercesImpl</artifactId>

<version>2.9.1</version>

</dependency>

<dependency>

<groupId>xml-apis</groupId>

<artifactId>xml-apis</artifactId>

<version>2.0.2</version>

</dependency>

<dependency>

<groupId>ical4j</groupId>

<artifactId>ical4j</artifactId>

<version>0.9.16-patched</version>

</dependency>

</dependencies>

--

--