ADempiere: How To Use Scala For Customisations
Scala is becoming an increasingly popular language and for many companies/developers it's a superior alternative to Java. ADempiere open source ERP/CRM, is written in Java but since Scala runs on JVM and has very good Java interoperability, it's very easy to customise ADempiere with Scala.
We'll see how it can be done.
The only things you're going to need is
- ADempiere binaries. You can either download them from SourceForge or build it directly from source with RUN_build (at the time of this writing 3.7.0LTS was the latest).
- JDK 1.6
- Scala 2.10.x (at the time of this writing 2.10.2 is the latest)
- SBT 0.12.x (at the time of this writing 0.12.4 is the latest)
I have created a template project which is hosted on github to speed up things for people. First clone it: git clone https://github.com/bahmanm/adempiere-scala.git customization .
This project (dependencies and build process) is managed by SBT which is a thin layer over Apache Ivy which tries to have the best of both the Ant and Maven worlds.
If you take a look inside the customization directory you just cloned, you'll see a directory structure like the image below . The description for each
- lib/: For those libraries that don't exist in public or your local Ivy repositories, you just need to drop the jar file into this folder and SBT will take care of it for you.
- project/: This directory is used by SBT and currently contains plugins.sbt which is the place to add new plugins to your customisation project. Right now there are three plugins defined for the project: sbt-assembly, sbteclipse and sbt-idea.
- src/main/: Put your main Java or Scala files or resources in this folder to have them in your final customization.jar.
- src/test/: Put your test classes along with resources required for testing this folder.
- build.sbt: This file is where build parameters are defined for SBT.
There is one modification that has to be done manually to the build definition file (I plan to automate this in near future). Open build.sbt in a text editor:
Please change lines 12 and 14 to denote the correct version of Scala you have on your system and the proper home of Scala installation path.
Also change line 16 to point to your JDK installation home
How To Use
Well, using this template is very straight-forward. Just copy Adempiere.jar, AdempiereCLib.jar and AdempiereSLib.jar from your ADempiere installation directory to the lib/ folder and you're done.
You can use the following commands in SBT shell to help you with your development:
- sbt test: To run all your tests and get a comprehensive report of successes and failures.
- sbt assembly: To package your customisations into one single Jar file named customization.jar
- sbt compile: To compile your code.
- sbt ~ compile: To have SBT recompile your sources whenever you make a change and save.
- sbt console: To have a Scala console (REPL) pre-loaded with your customizations and dependencies. Perfect for exploratory programming.
You may be wondering how can you use this with Eclipse; let SBT take care of that. Use sbt eclipse to have SBT generate the Eclipse project structure for you. After that it's just importing the project into Eclipse.
If you want to develop in Eclipse using ADempiere sources instead of Adempiere.jar, AdempiereCLib.jar and AdempiereSLib.jar, remember to remove these jar files from the build path of the project and add the required project to the build path instead.
Intellij IDEA Support
If your preferred IDE is IDEA, use sbt gen-idea to have SBT generate the IDEA project structure for you. Now just open the project in IDEA and voila!
- The jar files Adempiere.jar, AdempiereCLib.jar and AdempiereSLib.jar are required for your customizations to compile. However they are not included in the final customization.jar
- The above jar files are available only after the RUN_setup has been run in your ADempiere installation directory.