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:?"Usage: $(basename $0) </path/to/>"}

cp -f $EWSJavaAPI_BIN .
fileNameAndExtension=$(basename "$EWSJavaAPI_BIN")
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
curl -O
curl -O
curl -O
cd ../
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.


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.

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