Adding external library (.jar) to MPS

Hello

I am trying to import external java code in a .jar file into MPS. I followed these (https://mps-support.jetbrains.com/hc/en-us/community/posts/206614165-How-can-I-import-external-JARs-into-my-generator-project) instructions as best as possible: I could not find a “Models” button so I used the “Sources” button instead and when adding the .jar to the Library I get the following dialogue.

I tried them all and it does not seem to make a difference.

Everything seems to work fine up until when I want to use it in another solution/language: I can find my classes in the search dialogue (ctrl + r) but when I try to add it (enter/double click) the code keeps the same. Something is happening though since the reference is added.

Here some more information about my settings:

 

 

Any Ideas what I am doing wrong?

Thank you

Regards

Florian

5 comments
Comment actions Permalink

Yes, it works just like java import in such case, so you can only use it, but not edit, because it is analog of library.

To simplify copy of content from java sources, there are actions 'Paste as Java Statements', 'Paste as Java Class Content'.
Also you can import directory with sources with 'Models from java sources' action, which is available on solution.

1
Comment actions Permalink

Thanks for your answer, but unfortunately it did not solve my problem. I tried that where possible (only for Languages, correct?), but it makes no difference.

0
Comment actions Permalink

Why did you use Language for this?
If you just want to use classes from this jar as baseLanguage classes, then you probably should use Solution instead.

With Solution it is all the same with model roots: you can remove default one, add java_classes model root (folder with jar file), mark jar file(s) as sources.
And that should be it - under Solution there will be stub models with package structure and bl classes/interfaces/enums as roots.

What do you mean by "when I try to add it (enter/double click) the code keeps the same"? After using Ctrl+R for other solution/language first time, you should get "Module Import" dialog, asking to add module dependency automatically. Also you can check that stub model is added to model with current root in Dependencies tab as @java_stub model.

0
Comment actions Permalink

Well, it seems I did it all correctly. The only thing I did not realize is, that ctrl+r only adds the references. If you want this class in your code, you have to add it manualy afterwards. Well, I am sure I tried this a thousand times before without success. But it is working now, so thank you all for your help.

0

Please sign in to leave a comment.