Integration with Java
Integration with Java
There are a few ways to integrate with Java-based technology and obtain the ESDL Java source code. This can be obtained manually using option 1, but we also provide a external maven repository and maven tools to generate the source code on the command line.
1. Use our maven repository
Add the following repository entry to your
pom.xml
file:You can then add the ESDL dependencies like so again in the pom.xml file:
Add the required EMF dependencies
You need the following dependencies in your pom.xml
when using EMF-based ESDL:
You can also manually extract the main EMF-jar files from your local P2 Eclipse repository and add them to your classpath. You require the following EMF-jars:
If these dependencies are added to your application, ESDL can be used in the Java code.
2. Command line code generation
Clone the https://github.com/EnergyTransition/ESDL.git repository locally. Then execute:
(Optional) If you want to be able to extend the ESDLPackage to create your own implementations for the ESDL classes, please manually add this constructor definition…
… to the
EsdlPackageImpl.java
class inESDL/esdl/src-gen/esdl/impl/EsdlPackageImpl.java
You can then add the folder ESDL/esdl/src-gen to the build path of your code in your IDE.
Don't forget to add the EMF dependencies mentioned above.
3. Use the Eclipse platform for code generation (and application creation)
When loading the ESDL project into Eclipse, you can right-click the esdl.genmodel
file to generate the ESDL model Java code. Then use this project in other Eclipse based plugins.
This is currently used for the Edit, Editor and Designer plugins: they are Eclipse plugins that leverage the feature-rich Eclipse platform. Explaining how to do this can be read elsewhere on the internet. Options include using Sirius to create the Designer plugin, using EMF Forms to create attractive UIs to edit model instances, or creating a stand-alone ESDL-based application using Eclipse RCP.
Note: this approach is outdated now and hasn't been tested recently, we mostly create stand-alone Java applications outside of the Eclipse environment using the maven repository and dependencies.
Examples
E.g. creating an Energy System with an Area programmatically:
The following code allows you to load and save ESDL-model instances:
Loading of an ESDL-file
If the models grow large with a lot of internal references, add the following lines to speed up the loading of the files:
Saving an ESDL-file
Saving to an ESDL-file is as follows:
Last updated