Medea provides an Ant build file with targets to transform and build predefined components and applications.
The build file is located in the res directory. It uses configuration parameters defined in build.properties file. These files are copied in every project directory.
Standard directories are defined as properties in build.xml:
Created in project directory:
In installation directory:
Targets init and copy_res take parameters like project directory and name from build.properties 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 build.properties: 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 targets like compile_ejb, jar_ejb, deploy_app compile, package and deploy components and applications.
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: http://www.ibm.com/developerworks/library/os-ecemf3/.
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 build.properties in res directory:
projectName=quickstart modelFile=c:/projects/medea/model/quickstart_MagicDraw_11_5.xml # directory where the generated project will reside projectDir=/projects/quickstart # package name that will be prepended to all packages in the model, like 'com.mycompany'; set it to void not to add anything basePackage=void basePackageDir= ...
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.
You can try building a CRUD web application based on the same model:
C:\projects\quickstart>ant all_crud_ejb ... ... jar_app: [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 redeploy_app: [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 all_crud_ejb: BUILD SUCCESSFUL Total time: 1 minute 9 seconds
If the application has deployed correctly, you can see it in the browser:
Other targets in the build file can transform and build Struts, EJB, Webservices and other applications. Please examine the Targets section of this documentation.