JaMoPP Basic Tutorial

Ken Webb 2010-04-16T13:40:40Z

Having discovered the JaMoPP website and related projects, the first thing I wanted to do was try out a sample application. Figure 1 in the paper Construct to Reconstruct - Reverse Engineering Java Code with JaMoPP (by Florian Heidenreich, Jendrik Johannes, Mirko Seifert, Christian Wende) shows the source code for a simple Java class, and the corresponding model representation created by JaMoPP. That figure is also available on the EMFText Java5 page. For my purposes, this is a perfect application to get started with.

The paper does not go into details, and in fact I was unable to find a detailed description of exactly what I need to do to make the JaMoPP transformation from code to model happen. After some trial and error, and searching for clues online, I was able to get it to work. I'm writing this tutorial to help others just starting out with JaMoPP, and so I'll remember the next time I use it. Note that this is just what worked for me, and it's probably not the best way.

My current software development environment is Eclipse 3.5 (Galileo, Eclipse IDE for Java EE Developers) with Sun Java 1.6, running on Ubuntu 9.10 (Karmic Koala).

The first thing I did was create a new Java project in Eclipse, which I called jamoppTest1. I created a new package called test, and created a new Java class called Elephant. The Elephant class, as found in the paper, is as follows. I added the line package test;.

package test;

/**
 * An Elephant can be used to eat
 * bananas and carry heavy loads.
 */
public class Elephant {
    private boolean tired = false;
    
    public static void main(String[] args) {
        // here we go
        Elephant dumbo = new Elephant();
        if (dumbo.isTired()) {
            return;
        }
        dumbo.eatBananas();
    }
    
    public boolean isTired() {
        return tired;
    }
    
    public void eatBananas() {
        // TODO implement eating
    }
}

Because this is an exercise in using JaMoPP, the next step is to get the JaMoPP software from their website. As suggested on the download page, I used Eclipse to do this. Select Install New Software on the Eclipse Help menu. Press the Add button, and fill in Location: as:

http://emftext.org/update/

I filled in JaMoPP as the Name:.

Eclipse then presented a list of available software from that site. I selected JaMoPP (Java Model Parser and Printer), and then pressed the Next button. It was a large download. Once it completed, I restarted Eclipse.

At this point I wasn't sure what to do. I was unable to find anything directly accessible from the Eclipse GUI that's specific to JaMoPP or EMFText. An item in the JaMoPP mailing list suggested that I should download a jar file and run a specific Java class. I downloaded jamoppc.jar and org.emftext.language.java.jamoppc.JaMoPPC.java . I added jamoppc.jar to my project buildpath, and added JaMoPPC.java to a new package in my project. I ran JaMoPPC using an Eclipse Run Configuration, with the following arguments:

./src/test ./src/test

The software ran and created the following files, in addition to a large number of .class.xmi files in separate packages.

Elephant.java.xmi
java.ecore
primitive_types.ecore

You may have to refresh (F5) the Package Explorer to see these files. Right-click Elephant.java.xmi and select Open With > Sample Reflective Ecore Model Editor. You should be rewarded with the following model representation of the Java code, which is the same as what's shown in Figure 1 of the JaMoPP paper.

Note that the model contains all the same information that's in the Elephant class.

My biggest question at this point is: should I continue to use the jamoppc.jar library, or can I use the various org.emftext and org.reuseware plugin jar files that were downloaded from emftext.org/update/. It's not clear to me yet what all the pieces are, and how they should be used. I'll continue getting to know the Dresden tools, and will record what I learn in these pages.

Continue on to part 2 of this basic tutorial.

return to main page