In an earlier post, I identified ISO20022 as a model-driven success story. Here, I give some other examples of model-driven from e-Government and telecommunications. They are not all at the same level of maturity, but the reason why a model-driven approach makes sense is the same.
Debugging MagicDraw Plug-ins in Eclipse
June 12th, 2012
Eclipse IDE is a great environment for debugging, and very useful for MagicDraw plug-in developers. You’ll find information on how to debug the plug-in in Eclipse in the The MagicDraw OpenAPI UserGuide (located in the ‘manual’ directory of your MagicDraw installation directory). This works great for small plug-ins, but we ran in to a few problems when trying to debug some larger ones. In this post, we outline some of the problems we encountered and how we resolved them.
To make things clear, we will follow the steps outlined in the OpenAPI UserGuide. We’ll show where we couldn’t follow the steps exactly, and what we had to do.
The post is based on MagicDraw Version 17.0.1 and Eclipse Indigo Service Release 2.
Step 1: Create Java Eclipse Project for MagicDraw Plug-in
We already had an existing project. We didn’t want to create a new one, so we had to skip this step. However, we did need to add all of the MagicDraw libraries to the project’s build path. Just like the guide recommends, we created a user library in Eclipse, which we called ‘MagicDraw’, and added it to the project’s build path.
We had previously developed some smaller plug-ins(that we didn’t debug in Eclipse), and had already added some libraries to the build path. These were MagicDraw specific jar files, such as md_api.jar, md.jar, md_common_api.jar, etc. If you have added any, it’s best to remove them before adding the user library you’ve created, because they may not be as up to date as the libraries your current MagicDraw version uses. We then added all of the libraries we need for our project, for example JAXB and Xbean libraries(it doesn’t matter if there are similar libraries in the user library you created). Some of the libraries may conflict with MagicDraw’s, but they are necessary, as you may have a different version than the one contained within the MagicDraw lib folder.
To ensure no conflict occurs, when you start, or debug MagicDraw in Eclipse – right click on your project → Build Path → Configure Build Path… then, click the ‘Order and Export’ tab. Once there, we made sure that the order was as follows: our source project was on top, followed by the JDK, then our ‘MagicDraw’ user library was located ABOVE any other jar, or library that we added to the project. After that, there was no particular precedence.
Step 2: Create Plug-in Main Class
Follow step 2 from the MagicDraw OpenAPI UserGuide, “Each MagicDraw plug-in main class must extend the com.nomagic.magicdraw.plugins.Plugin class and implement its methods ……… However, please remember that the Eclipse generated implementation for isSupported() and close() methods returns the false value which should be changed to true for enabling the plug-in initialization and disposing.”
Step 3: Prepare Plug-in Descriptor File
Step 3 from the MagicDraw OpenAPI UserGuide says “The plug-in descriptor XML file should be written as described in “Step 4: Start MagicDraw From Eclipse Environment” on page 23 and placed to the <MagicDraw installation directory>\plugins\my_plugin_name directory.
Please note, that even plug-in descriptor file contains information about runtime plug-in jar, it is not necessary to build and deploy this jar to plug-in directory while plug-in is developed under Eclipse IDE.”
So, just add a plugin.xml file to the <MagicDraw installation directory>\plugins\my_plugin_name directory. You won’t need anything else. (This step also mentions different properties that are needed in the plugin.xml file, but they are needed, only when the plug-in is actually deployed in MagicDraw. This is outside the scope of this post but, we will come back to this in a future one.)
Our plugin.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?> <plugin id="nomos.plugin.five" name="Nomos Plugin Five" version="1.6" provider-name="nomos" internalVersion="15010" class="com.nomos.noMagic.NomosNoMagicPlugin5"> </plugin>
‘com.nomos.noMagic.Plugin5′ is the package in our Eclipse project, that contains our plug-in’s source code. NomosNoMagicPlugin5 is the plug-in main class in that package, mentioned in Step 2.
Step 4: Start MagicDraw From Eclipse Environment
Create a new debug, or run configuration, and add ‘com.nomagic.magicdraw.Main’ as the ‘Main class’. Make sure your source project is set as the ‘Project’. MagicDraw output can be redirected to Console by specifying the -verbose key in ‘Program arguments’ under the ‘arguments’ tab. In the VM arguments add -Xmx800M -XX:PermSize=4M -XX:MaxPermSize=135m -Dinstall.root=”someDrive/someFolder/MagicDraw”. Then click debug, or run! You can also specify -Dmd.plugins.dir=”someDrive/CustomPluginFolderWithPlugInDotXml/” if MagicDraw needs to be loaded with custom plug-ins only.
Do you notice any of these problems?
In the Eclipse package folder there are .properties files
Well, they shouldn’t be there. Remove the files from the package and try again. The package should only contain the files that are vital for your plug-in.
There is more than one plug-in in the project
We work on a few things for MagicDraw, and test our plug-ins in MagicDraw on its own, so we have already imported some of them via the ‘Resource/Plugin Manager’. Go to the package (in Eclipse) containing any plug-in that is installed in MagicDraw and exclude them from your project’s build path. Rebuild your workspace and try again.
Still having an issue?
Leave a comment!
Check out the rest of the MagicDraw OpenAPI UserGuide.
Read about our MagicDraw plugins.