Transforming and building with Ant

Medea provides an Ant build file with targets to transform and build predefined components and applications.

Build files

The build file is located in the res directory. It uses configuration parameters defined in file. These files are copied in every project directory.

Directories, common libraries and resources

Standard directories are defined as properties in build.xml:

Created in project directory:

  • src source files to build
  • gen generated source files
  • build compiled class and other files ready for packaging into jar files
  • dist components and applications ready for distribution
  • htdocs generated web tier files like jsp, css and javascript files
  • config generated configuration files and deployment descriptors
  • lib project libraries

In installation directory:

  • style XSLT stylesheets
  • lib library for Medea's merge task and other future Medea libraries
  • res build files and common resources copied to projects
    • config standard configuration files and deployment descriptors
    • htdocs standard jsp, css and javascript files
    • thirdparty third party libraries needed for building components and applications

Project creation and initialization

Targets init and copy_res take parameters like project directory and name from file, create directories and copy static resources.

Medea can transform XMI files in different formats. However, for transformation to work, the namespace should match the one defined in the templates. A utility target namespace replaces UML namespace declaraion in the source XMI file. Execute this target before running code generation targets.


Target trans executes XSLT transformer Saxon with arguments taken from modelFile for the input XMI, template for the name of the XSLT, basePackage for the containing packages etc.

Other transformation targets defined in the file like trans_data, trans_ejb execute trans with a set of templates needed to generate code for a given component. These targets are described in other sections.

Build and deployment

Build targets like compile_ejb, jar_ejb, deploy_app compile, package and deploy components and applications.

Code merging

Most Medea templates generate code with embedded Java comments that allow the use of Eclipse's JMerge tool. Generated code can be merged to embed custom code from user's sources. Generated and user code are located in different directories, gen and src. A special target merges code after generation and before the build. If no merge is required, the target simply copies a file from gen to code. Merge configuration file is located in the installation directory: merge.xml. Please consult JMerge documentation for merging rules and configuration:

EJB Example

The following set of Ant targets will create a project for the quickstart example, generate sources for an ejb component, merge, compile, package and deploy. Note that after creation of the project other targets can be executed from the project directory.

Edit in res directory:


# directory where the generated project will reside

# package name that will be prepended to all packages in the model, like 'com.mycompany'; set it to  void not to add anything

Create project by copy_res, move to the project directory and execute other targets: namespace trans_data trans_ejb merge compile_ejb jar_ejb redeploy_jar:

 C:\projects\medea\res>ant copy_res
 C:\projects\medea\res>cd C:\projects\quickstart
 C:\projects\quickstart>ant namespace trans_data trans_ejb merge compile_ejb jar_ejb redeploy_jar

These targets will transform the model into the source code for value object (data), CMP and Session EJBs, configuration files; compile, jar and deploy.

CRUD Example

You can try building a CRUD web application based on the same model:

C:\projects\quickstart>ant all_crud_ejb
    [mkdir] Created dir: C:\projects\quickstart\build\app
     [copy] Copying 3 files to C:\projects\quickstart\build\app
    [mkdir] Created dir: C:\projects\quickstart\build\app\META-INF
     [copy] Copying 2 files to C:\projects\quickstart\build\app\META-INF
      [jar] Building jar: C:\projects\quickstart\dist\quickstart.ear

   [delete] Deleting: C:\Progra~1\jboss-4.0.4.GA\server\default\deploy\quickstart.ear
     [copy] Copying 1 file to C:\Progra~1\jboss-4.0.4.GA\server\default\deploy


Total time: 1 minute 9 seconds

If the application has deployed correctly, you can see it in the browser:

CRUD J2EE application

Other targets in the build file can transform and build Struts, EJB, Webservices and other applications. Please examine the Targets section of this documentation.