Friday, June 29, 2012

Microsoft EWS Managed Java API Installation from a POB recipe

It's been a year since I posted about EWS Exchange API and I wanted to give the managed API a try again.

For some reason Microsoft is still reluctant to put their EWS Managed Java API in a repository from where we can check out the source code. The ant script is buggy (won't build out of the box from command line) and even though at the time of this writing the version is 1.1.5 it still generates the resulting jar file as 1.1.0.

With the spirit of automation I am providing here a Plain Old Bash Recipe to build the project. The only thing that you have to do manually is download the zipped file as Microsoft enforces a license agreement every time you try to download (Again no real versioning repository exists with the project content). After running this recipe you will end up with the correct version number in the jar file. No need for Eclipse, just command prompt and ready you are to upload the artifact to your Maven repo.
#!/usr/bin/env bash -ex
#
# @author Nestor Urquiza
#
# Builds Microsoft EWS Managed Java API
# 

EWSJavaAPI_BIN=$1
: ${EWSJavaAPI_BIN:?"Usage: $(basename $0) </path/to/EWSJavaAPI.zip>"}

cp -f $EWSJavaAPI_BIN .
fileNameAndExtension=$(basename "$EWSJavaAPI_BIN")
extension="${fileNameAndExtension##*.}"
fileName="${fileNameAndExtension%.*}"
rm -fR $fileName
unzip $fileNameAndExtension

cd $fileName
sed -i '' 's!<javac srcdir="${src}" destdir="${build}"/>! \
              <javac srcdir="${src}" destdir="${build}"> \
                <compilerarg value="-Xlint"/><classpath> \
                <fileset dir="${basedir}/lib"> \
                    <include name="**/*.jar" /> \
                </fileset> \
                </classpath> \
              </javac>!g' build.xml


cd lib
curl -O http://repo1.maven.org/maven2/commons-codec/commons-codec/1.4/commons-codec-1.4.jar
curl -O http://repo1.maven.org/maven2/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar
curl -O http://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
curl -O http://repo1.maven.org/maven2/jcifs/jcifs/1.3.17/jcifs-1.3.17.jar
cd ../
ant
mv lib/EWSAPI-1.1.0.jar lib/$fileName.jar
I have taken the opportunity to update my project in Google Code repository which now shows a simple SendMail class that sends the members of a given distribution list.

2 comments:

PT said...

Hi. I am desperate to get hold of the EWS Java API 1.1 as the currently available version (1.2) uses a newer version of Java that the one we currently use. I don't suppose you have the origional 1.1 download somewhere still do you? Thanks in advance if you can help.
Pete

Nestor Urquiza said...

PT, drop me an email so I can send you the jar. I was able to find 1.1.5. However I have to say you should really consider upgrading Java or using then straight web services as per my first blog post. As far as I can tell the ewsapi was really buggy in those early versions. Not that I am so sure it is not buggy still as I am not using anything related to exchange at this precise moment. Best, - Nestor

Followers