I was asked a question the other day about using Java with EA and admitted I didn’t know all the answer. It’s been a long time since I developed in Java, not through choice, but as customers wanted something else. So I was inspired to have a look a quick look at what is possible, not least as I like to check things out, and feel comfortable that whatever information I provide has some background.
Now it must have been about 10 years ago that I used Java, so the first task was to get the relevant tools. Clearly all changed – so a quick check and seemed like I should give eclipse a go as it appears to be a major player – and hopefully as easy to use as previous tools.
So armed with enthusiasm for my new experiment I downloaded eclipse and within an hour or so (time flies when having fun) I had installed a new JDK and IDE application and was able to run the Java code samples provided by Sparx. Just got that glow when things go right.
Just in case you want to do the same, here are the steps I went through:
- Download and install Java JDK – (http://www.oracle.com/technetwork/java/javase/downloads/index.html)
- Download and install eclipse http://www.eclipse.org/downloads/ – I installed eclipse standard
- Copy the EA Java code samples from under the Sparx EA installed directory to a suitable working location e.g. under the workspace configured as part of the first time run of eclipse. I spent 30 mins with the eclipse getting started tutorial as it was completely new to me and was really worth while to get to know the UI.
- Create a new eclipse project for the sample; and Importantly set the references to the EA Java libraries (on my system C:\Program Files (x86)\Sparx Systems\EA\Java API) – the readme file describes what is needed.
- Run project – with a few minor issues with ensuring package names were correct (eclipse clearly indicated the errors) – it all worked.
So the samples work but can I write some code.
In looking at the sample code, Sparx have set up a framework supports the running of their examples, so the obvious route was to add another example supporting the interfaces that has been defined. The process was to create a new example using an existing example as the template and:
- create a new class
- copy the key parts from and existing example; insure it implements IExample interface
- edit the toString and getDescription methods
- change the runExample method to perform the functions you require – add other methods/classes etc as needed
It took me a little while to become accustomed to the way eclipse works, especially the lack of auto-complete that is provided in VS – but apart from that it all worked fine as I incrementally built and tested my example app. No big problems or surprises for me.
So I had verified that I a Java client could work and I could add some of my own functionality – build block 1 done. I did find that running the Java app appeared a lot slower than using other windows apps, but without delving deeper not sure if this is just eclipse or EA’s library or a combination associated with my environment – so not judgement on this yet.
Having demonstrated to myself that the basics work I’m happy. I know I can’t develop a Java Add-In as Sparx don’t support that (yet?) – but what about calling Java applications from EA? Does this work – are there other ways of interacting? Can a Java applet access EA?
Well I’m off to do some more experimenting to see what can be done – and hope to report back soon.