I’ve been working as solution architect for SAP Hybris Commerce solutions for quite some time. In this article, I am going to explain how can we use Clojure with SAP Hybris Commerce.
As you know, SAP Hybris Commerce has already supported to create extensions with Scala and Groovy by providing template extensions. If you want to use Scala for SAP Hybris Commerce, you can easily create an extension with the yscala template, and then SAP Hybris Commerce will compile Scala code for you.
So, we will follow the same method to integrate Clojure with SAP Hybris Commerce. We need to create a template extension, let’s call it yclojure, and also another extension to keep Clojure dependencies and also provide some ant tasks and classpath entries to compile Clojure code for use in SAP Hybris Commerce, clojurenature.
Let’s start with the clojurenature extension to provide Clojure dependencies and our ant macro definition to compile a given Clojure namespace with given classpath entries.
Then we will prepare the yclojure extension to provide us the right directory structure, clojurenature extension as dependency, the initial Clojure namespace, and other properties to make sure our template extension works well with SAP Hybris Commerce.
And finally, we can create a new extension with our yclojure template to write some Clojure code. So, I am going to create a new extension called clojurelib and write some very simple Clojure code to use FlexibleSearchService.
Let’s create a new extension useclojure, add the clojurelib extension as dependency, and also write an unit test to make sure our Clojure code working as expected.
Run the test...
It’s all done. Now we have SAP Hybris Commerce platform with a Clojure extension. You can find clojurenature and the yclojure extension on GitHub.