Properly import open api .jar files for macro development

Starting point for “ask and learn more about MagicDraw”

Moderator: Moderators

Properly import open api .jar files for macro development

Postby ohs18 » Mon Mar 15, 2021 1:07 pm

Hi,

I am using eclipse to try and write some macros in Cameo. Currently I am not trying to do anything too difficult, just some basic stuff to get familiar with writing them and using the openAPI. However, I have been having trouble with importing different classes from the openAPI in my code. For example, I have tried importing the following classes for use in my code:

import com.nomagic.magicdraw.core.Aplication;
import com.nomagic.magicdraw.uml.Finder;
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Package;
import com.nomagic.uml2.ext.magicdraw.classesmdkernel.Class;
import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper;
import com.nomagic.magicdraw.uml.ClassifierFinder;

I have gotten errors on the first and fourth import statements saying that they cannot be resolved, while the other 4 seem to be fine. In eclipse, I have gone and created a user library that contains what I believe to be all the .jar in the lib file of my Cameo install directory. I'm not sure why I am getting an error with some import statements and not all of them, considering how similar some of them are.

Any help with this is greatly appreciated.

Thanks in advance
ohs18
Forum Newbie
Forum Newbie
 
Posts: 17
Posts Rating:1
Joined: Wed Jan 20, 2021 7:08 pm

Re: Properly import open api .jar files for macro development

Postby ogirdor » Tue Mar 16, 2021 7:39 am

Hi ohs18,

it actually involves some work to find out which jars to include. You first have to determine which plugins (if any!) you will need. Then you need to look into the plugin.xml for that plugin and include all jars mentioned there. If that plugin requires other plugins (look for "required-plugin" entries in the plugin.xml), then you need to include all jars in the plugin.xml for that required-plugin.

If you do not need any external plugin, you do not need any jar from the plugins directory.

Blindly including all jars in the plugins directory can lead to conflicts.

Hope this helps.
ogirdor
Forum Beginner
Forum Beginner
 
Posts: 58
Posts Rating:17
Joined: Wed Jun 03, 2020 4:41 am

Re: Properly import open api .jar files for macro development

Postby ogirdor » Tue Mar 16, 2021 7:46 am

You will also need the jars in MAGIC_DRAW_INSTALL_DIRECTORY/lib and its sub directories, as explained in the documentation (https://docs.nomagic.com/display/MD190s ... elliJ+IDEA)
ogirdor
Forum Beginner
Forum Beginner
 
Posts: 58
Posts Rating:17
Joined: Wed Jun 03, 2020 4:41 am

Re: Properly import open api .jar files for macro development

Postby ohs18 » Tue Mar 16, 2021 9:28 am

Hi ogirdor,

Thanks for the response. I just have some follow up questions to this, and I apologize if some of these are basic/trivial, but I am still working on understanding development for Cameo.

My first question as a follow up is is there a difference between the jar files needed when developing macros to include in the macro engine tool versus the jar files needed when developing plug-ins for Cameo? I have included all of the jars in my Cameo_install_directory/lib already, and I was under the impression that all of the jars contained in the lib folder would contain all the classes located in the javadocs here: http://jdocs.nomagic.com/190/. As it turns out, I was spelling a couple of things wrong in the import statements and all of them seem to be working now that all of the jar files from the lib folder are added. However, I still think I am not quite understanding the difference between developing macros for Cameo/MagicDraw versus developing plugins, and the subsequent difference in the need for the jar files located in the plugins directory versus just the jar files in the lib directory.

My other question to you would be is there a way to know without combing through the various plug-in folders in the Cameo install directory what folders and jar files would be needed to be included in the build path of a project if I wanted to use a specific class from the javadocs? For example, if I wanted to use methods from the com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Classifier interface, would I know I need to go into the plug-in folders and look for the jar file(s) that contains this class? Or is there an easier way of knowing what jar files to add?

Again, thank you for the help.
ohs18
Forum Newbie
Forum Newbie
 
Posts: 17
Posts Rating:1
Joined: Wed Jan 20, 2021 7:08 pm

Re: Properly import open api .jar files for macro development

Postby ogirdor » Tue Mar 16, 2021 9:40 am

Ok, I actually was referring to the way I proceed when developing plugins.

For macros it might be different. Here I simply followed the information in the documentation: https://docs.nomagic.com/display/MD190s ... vy+scripts
(although I personally use IntelliJ IDEA instead of Eclipse)
ogirdor
Forum Beginner
Forum Beginner
 
Posts: 58
Posts Rating:17
Joined: Wed Jun 03, 2020 4:41 am

Re: Properly import open api .jar files for macro development

Postby ohs18 » Tue Mar 16, 2021 10:21 am

Ok. Thanks for the help. I see now where they explain what jar files to load for macros.
ohs18
Forum Newbie
Forum Newbie
 
Posts: 17
Posts Rating:1
Joined: Wed Jan 20, 2021 7:08 pm


Return to New to MagicDraw

Who is online

Users browsing this forum: No registered users and 2 guests

cron