MPS 3.0 - adding external jar to project

  • 14
  • 117

How can I add external jar file to project? It seems that the way I added jar in 2.5 doesn't work anymore - I can't find compiled java stubs model after import.

I also tried to create a "Model from Java Sources", but this thing doesn't work also (this must be MPS-18147 bug).
Alexander Shatalin pointed to the solution in comments of the bug above:

@Askar: it should be possible to create model root pointing to the jar and loading .class files from there as model elements, but this looks like unrelated question.

Model roots (language properties dialog) is the way to do this. However, be advised that you will need to work hard to add each model root in MPS3, you need to select a jar file using the panel on the right, which looks nothing like a file dialog and is particularly not user friendly (at least on Mac). Note that you cannot select multiple jars to create several new roots at once. Clicking on a previously defined model root is also likely to change the path the root points to to something arbitrary. Try to remember the name and location of the jar file before you click. The UI seriously needs some improvement.

I'm glad I'm not the only one who dislikes the new interface for importing stub models (Mac here as well).

This might be not enough to compile the code though. If "missing class" errors appear pointing to a library you added as a model root, you also should add this library in "Java sources" tab.

@Fabien
Also, on Windows for this select-directory-component mouse wheel behaves differently from how it behaves for standard file select dialog - instead of scrolling multiple list items, it scrolls multiple pixels, which makes this control not very user friendly )


Please somebody could provide details of how to attach a jar file so that I could use them in my generators. I have spent two half days for it without success. I am using MPS 3.0.Thanks in advance.

First you need to add java stub model root to Generator from its properties:
Screenshot from 2013-10-17 17:43:10.png

Then choose jar file:
Screenshot from 2013-10-17 17:43:43.png

Now you will get stubs in your Generator:
Screenshot from 2013-10-17 17:44:05.png

Then just import stub models that you need to main@generator model to use them.

Thanks a lot. That’s exactly how you import java stubs (jar files) to MPS 3.0.

Hi, I managed to get the external jars under the stubs inside the solution. I can refer to classes in the jars from within MPS. But when I build the solution I get the following error message:

IntelliJ IDEA is required for compilation

This is weird, since the imported jar files contain .class files, i.,e. compiled Java code. I don't expect this to be compiled at all. Any idea what went wrong?

Jos

Hi Jos!

You need to open solution settings -> choose "Java" tab -> select checkbox "Compile in MPS"

Screenshot from 2013-11-19 20:08:51.png

Actually, the generated Java text should not be compiled at all. It is picked up by an Eclipse instance that will compile it. Can this be done?

Tnx, that works.

BY the way, I also had to add the jar file under the java / libs tab to be able to run it. In addition to the above procedure.

I use a smartcard to connect to my TFS via Visual Studio 2012. VS does it well: asks for the smartcard's PIN then establishes a connection. Unfortunately I can't reach the same result via WebStorm. It tells "Forbidden". idea_output.txt contains several responses from the server which begin with
RABI>>>>>>>>>>>>>