Help with importing Java sources

I am just starting to play with MPS, a complete novice. I tried importing some Java sources using New Models from Java Sources. The resulting models have unresolved references to annotations defined in a Java library. How do I tell MPS where to find this Java library?

I tried creating a DevKit, added the Java facet, and added the JAR file as a library under the Java tab. I was offered the option to create models, along with a combo box of options that are meaningless to me. I chose java_classes. I added the DevKit as a used language of the model that contains the unresolved references. What more needs to be done?

Thanks in advance...
11 comments
Hi Alan
It seems to be related to http://youtrack.jetbrains.com/issue/MPS-19549
For references to get resolved it should be sufficient to have stub models for that library (in your case you were offered to create them when you added it as a library).

I'll be fixing it soon-ish. So far, please try hitting F5 (refresh) if you're in MPS ide, not in idea plugin.

Just in case, java stub models are java top-level structure (classes, fields, methods) recovered from class files (possibly in jars) and represented in models like BaseLanguage classes. They are needed for code written in MPS to reference those "external" things.

While libraries (that you added in module properties) are needed to actually compile against that library.
0
I think my question is more basic than this. I do not know what it means to import a Java library. If I go to Settings > Project Libraries and click the Add button, it brings up a dialog asking me to Enter a Library name. I have no idea what this means, and nothing I tried was useful. If I go to Project Structure and click on the + button, it will not let me select a JAR file. I explained my attempt to use a DevKit, which did not work, even after invalidating caches. (I don't see any Refresh command and F5 did not appear to do anything.) Please explain in terms of the MDS UI what I should be doing to import a JAR into a MDS project that includes base language classes that refer to declarations in the JAR. Thank you.

  Alan
0
Alan,  If I understand correctly, you tried Preferences>Project Libraries
(not Settings as you wrote). This is the wrong place to do it.

What you should be doing is projectTab> solution name> Module
Properties>Java>Libraries, once you are there, click the + at the bottom
and pick any number of jar files with the file dialog. If you need the
stubs, as Daniil indicated, do projectTab> solution name> Module
Properties, then click the + to add a model root.

Note that I am using the conventions used in my book (see
http://books.campagnelab.org and the free intro for what these conventions
are).

Fabien




On Thu, Apr 24, 2014 at 10:46 PM, Alan Snyder - Meta Programming System <
jetforum@jetbrains.com> wrote:

* Meta Programming System
<http://forum.jetbrains.com/forum/Meta-Programming-System> * > * Help
with importing Java sources
<http://forum.jetbrains.com/thread/Meta-Programming-System-964> * 10:46 pm<http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-2>  Alan
Snyder <http://forum.jetbrains.com/user/Alan%20Snyder>

I think my question is more basic than this. I do not know what it means
to import a Java library. If I go to Settings > Project Libraries and click
the Add button, it brings up a dialog asking me to Enter a Library name. I
have no idea what this means, and nothing I tried was useful. If I go to
Project Structure and click on the + button, it will not let me select a
JAR file. I explained my attempt to use a DevKit, which did not work, even
after invalidating caches. (I don't see any Refresh command and F5 did not
appear to do anything.) Please explain in terms of the MDS UI what I should
be doing to import a JAR into a MDS project that includes base language
classes that refer to declarations in the JAR. Thank you.

Alan

   Daniil Elovkov <http://forum.jetbrains.com/user/Daniil%20Elovkov> @ 11:46
am<http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-1>

Hi Alan
It seems to be related to http://youtrack.jetbrains.com/issue/MPS-19549
For references to get resolved it should be sufficient to have stub models
for that library (in your case you were offered to create them when you
added it as a library).

I'll be fixing it soon-ish. So far, please try hitting F5 (refresh) if
you're in MPS ide, not in idea plugin.

Just in case, java stub models are java top-level structure (classes,
fields, methods) recovered from class files (possibly in jars) and
represented in models like BaseLanguage classes. They are needed for code
written in MPS to reference those "external" things.

While libraries (that you added in module properties) are needed to
actually compile against that library.

  JetBrains Forum | Build #175 (Apr/16/2014 6:53PM) | Feedback<http://confluence.jetbrains.net/display/JETF/Feedback>




--
Fabien Campagne, PhD – http://campagnelab.org

Assistant Professor,    Dept. of Physiology and Biophysics
          Institute for Computational Biomedicine
Associate Director,      Biomedical Informatics Core,
       Clinical Translational Science Center

Weill Medical College of Cornell University
phone:  (646)-962-5613  1305 York Avenue
fax:    (646)-962-0383  Box 140
New York, NY 10021

Do you speak next-gen?

See how GobyWeb can help simplify your NGS projects at
http://gobyweb.campagnelab.org
0
What you should be doing is projectTab> solution name> Module
Properties>Java>Libraries, once you are there, click the + at the bottom
and pick any number of jar files with the file dialog.


When I do this, I get a Model Roots dialog. MPS can try creating models for the specified locations, so that class files can be referenced from MPS models directly. Would you like to import models for the specified locations?

Should I do this? Which of the offered options should I select:

project
java_classes
default
obsolete
java_source_stubs

I have no idea what these options mean!

Thank you.

  Alan
0
You are looking at the Common tab. If you follow my instructions, you will
see that you need to pick the Java tab after you open the module properties
(projectTab> solution name> Module Properties>*Java*> Libraries)

This is to add a library. If you need first class models in addition to
just the classes (likely if you don't know the difference), add a model
root as well in the Common tab. I am adding a section to the book to
clarify what the various options mean. For now, I assume you want to import
a JAR file, then pick java_classes. (All of this is easier to explain with
screen snapshots.)


On Thu, Apr 24, 2014 at 11:36 PM, Alan Snyder - Meta Programming System <
jetforum@jetbrains.com> wrote:

* Meta Programming System
<http://forum.jetbrains.com/forum/Meta-Programming-System> * > * Help
with importing Java sources
<http://forum.jetbrains.com/thread/Meta-Programming-System-964> * 11:36 pm<http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-4>  Alan
Snyder <http://forum.jetbrains.com/user/Alan%20Snyder>

What you should be doing is projectTab> solution name> Module
Properties>Java>Libraries, once you are there, click the + at the bottom
and pick any number of jar files with the file dialog.


When I do this, I get a Model Roots dialog. MPS can try creating models
for the specified locations, so that class files can be referenced from MPS
models directly. Would you like to import models for the specified
locations?

Should I do this? Which of the offered options should I select:

project
java_classes
default
obsolete
java_source_stubs

I have no idea what these options mean!

Thank you.

Alan

   Fabien Campagne <http://forum.jetbrains.com/user/Fabien%20Campagne> @ 11:25
pm<http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-3>

Alan, If I understand correctly, you tried Preferences>Project Libraries
(not Settings as you wrote). This is the wrong place to do it.

What you should be doing is projectTab> solution name> Module
Properties>Java>Libraries, once you are there, click the + at the bottom
and pick any number of jar files with the file dialog. If you need the
stubs, as Daniil indicated, do projectTab> solution name> Module
Properties, then click the + to add a model root.

Note that I am using the conventions used in my book (see
http://books.campagnelab.org and the free intro for what these conventions
are).

Fabien




On Thu, Apr 24, 2014 at 10:46 PM, Alan Snyder - Meta Programming System <
jetforum@jetbrains.com> wrote:

* Meta Programming System
<http://forum.jetbrains.com/forum/Meta-Programming-System> * > * Help
with importing Java sources
<http://forum.jetbrains.com/thread/Meta-Programming-System-964> * 10:46
pm<
http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-2>
Alan
Snyder <http://forum.jetbrains.com/user/Alan%20Snyder>

I think my question is more basic than this. I do not know what it means
to import a Java library. If I go to Settings > Project Libraries and click
the Add button, it brings up a dialog asking me to Enter a Library name. I
have no idea what this means, and nothing I tried was useful. If I go to
Project Structure and click on the + button, it will not let me select a
JAR file. I explained my attempt to use a DevKit, which did not work, even
after invalidating caches. (I don't see any Refresh command and F5 did not
appear to do anything.) Please explain in terms of the MDS UI what I should
be doing to import a JAR into a MDS project that includes base language
classes that refer to declarations in the JAR. Thank you.

Alan

Daniil Elovkov <http://forum.jetbrains.com/user/Daniil%20Elovkov> @ 11:46
am<
http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-1
>

Hi Alan
It seems to be related to http://youtrack.jetbrains.com/issue/MPS-19549
For references to get resolved it should be sufficient to have stub models
for that library (in your case you were offered to create them when you
added it as a library).

I'll be fixing it soon-ish. So far, please try hitting F5 (refresh) if
you're in MPS ide, not in idea plugin.

Just in case, java stub models are java top-level structure (classes,
fields, methods) recovered from class files (possibly in jars) and
represented in models like BaseLanguage classes. They are needed for code
written in MPS to reference those "external" things.

While libraries (that you added in module properties) are needed to
actually compile against that library.

JetBrains Forum | Build #175 (Apr/16/2014 6:53PM) | Feedback<
http://confluence.jetbrains.net/display/JETF/Feedback>





Fabien Campagne, PhD – http://campagnelab.org

Assistant Professor, Dept. of Physiology and Biophysics
Institute for Computational Biomedicine
Associate Director, Biomedical Informatics Core,
Clinical Translational Science Center

Weill Medical College of Cornell University
phone: (646)-962-5613 1305 York Avenue
fax: (646)-962-0383 Box 140
New York, NY 10021

Do you speak next-gen?

See how GobyWeb can help simplify your NGS projects at
http://gobyweb.campagnelab.org

  JetBrains Forum | Build #175 (Apr/16/2014 6:53PM) | Feedback<http://confluence.jetbrains.net/display/JETF/Feedback>




--
Fabien Campagne, PhD – http://campagnelab.org

Assistant Professor,    Dept. of Physiology and Biophysics
          Institute for Computational Biomedicine
Associate Director,      Biomedical Informatics Core,
       Clinical Translational Science Center

Weill Medical College of Cornell University
phone:  (646)-962-5613  1305 York Avenue
fax:    (646)-962-0383  Box 140
New York, NY 10021

Do you speak next-gen?

See how GobyWeb can help simplify your NGS projects at
http://gobyweb.campagnelab.org
0
You are looking at the Common tab.


No, the dialog is from the Java tab:

Screen Shot 2014-04-25 at 6.23.15 AM.png


I selected java_classes, then went to the Common tab and added java_classes as a model root.

However, I am not seeing any evidence that a model was created from the JAR. Nothing new shows up in the right side pane of the Common tab.

  Alan
0
I see, this happens when you go directly to the Java tab, and you do not
yet have a model root configured for these jars. I was trying in a project
where the model root was already configured.


On Fri, Apr 25, 2014 at 9:46 AM, Alan Snyder - Meta Programming System <
jetforum@jetbrains.com> wrote:

* Meta Programming System
<http://forum.jetbrains.com/forum/Meta-Programming-System> * > * Help
with importing Java sources
<http://forum.jetbrains.com/thread/Meta-Programming-System-964> * 9:46 am<http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-6>  Alan
Snyder <http://forum.jetbrains.com/user/Alan%20Snyder>

You are looking at the Common tab.


No, the dialog is from the Java tab:

[image: Screen Shot 2014-04-25 at 6.23.15 AM.png]</_persistent/Screen%20Shot%202014-04-25%20at%206.23.15%20AM.png?file=29-3451&v=0&c=true>


I selected java_classes, then went to the Common tab and added
java_classes as a model root.

However, I am not seeing any evidence that a model was created from the
JAR. Nothing new shows up in the right side pane of the Common tab.

Alan

   Fabien Campagne <http://forum.jetbrains.com/user/Fabien%20Campagne> @ 12:04
am<http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-5>

You are looking at the Common tab. If you follow my instructions, you will
see that you need to pick the Java tab after you open the module properties
(projectTab> solution name> Module Properties>*Java*> Libraries)

This is to add a library. If you need first class models in addition to
just the classes (likely if you don't know the difference), add a model
root as well in the Common tab. I am adding a section to the book to
clarify what the various options mean. For now, I assume you want to import
a JAR file, then pick java_classes. (All of this is easier to explain with
screen snapshots.)


On Thu, Apr 24, 2014 at 11:36 PM, Alan Snyder - Meta Programming System <
jetforum@jetbrains.com> wrote:

* Meta Programming System
<http://forum.jetbrains.com/forum/Meta-Programming-System> * > * Help
with importing Java sources
<http://forum.jetbrains.com/thread/Meta-Programming-System-964> * 11:36
pm<
http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-4>
Alan
Snyder <http://forum.jetbrains.com/user/Alan%20Snyder>

What you should be doing is projectTab> solution name> Module
Properties>Java>Libraries, once you are there, click the + at the bottom
and pick any number of jar files with the file dialog.


When I do this, I get a Model Roots dialog. MPS can try creating models
for the specified locations, so that class files can be referenced from MPS
models directly. Would you like to import models for the specified
locations?

Should I do this? Which of the offered options should I select:

project
java_classes
default
obsolete
java_source_stubs

I have no idea what these options mean!

Thank you.

Alan

Fabien Campagne <http://forum.jetbrains.com/user/Fabien%20Campagne> @
11:25
pm<
http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-3
>

Alan, If I understand correctly, you tried Preferences>Project Libraries
(not Settings as you wrote). This is the wrong place to do it.

What you should be doing is projectTab> solution name> Module
Properties>Java>Libraries, once you are there, click the + at the bottom
and pick any number of jar files with the file dialog. If you need the
stubs, as Daniil indicated, do projectTab> solution name> Module
Properties, then click the + to add a model root.

Note that I am using the conventions used in my book (see
http://books.campagnelab.org and the free intro for what these conventions
are).

Fabien




On Thu, Apr 24, 2014 at 10:46 PM, Alan Snyder - Meta Programming System <
jetforum@jetbrains.com> wrote:

* Meta Programming System
<http://forum.jetbrains.com/forum/Meta-Programming-System> * > * Help
with importing Java sources
<http://forum.jetbrains.com/thread/Meta-Programming-System-964> * 10:46
pm<

http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-2
>
Alan
Snyder <http://forum.jetbrains.com/user/Alan%20Snyder>

I think my question is more basic than this. I do not know what it means
to import a Java library. If I go to Settings > Project Libraries and click
the Add button, it brings up a dialog asking me to Enter a Library name. I
have no idea what this means, and nothing I tried was useful. If I go to
Project Structure and click on the + button, it will not let me select a
JAR file. I explained my attempt to use a DevKit, which did not work, even
after invalidating caches. (I don't see any Refresh command and F5 did not
appear to do anything.) Please explain in terms of the MDS UI what I should
be doing to import a JAR into a MDS project that includes base language
classes that refer to declarations in the JAR. Thank you.

Alan

Daniil Elovkov <http://forum.jetbrains.com/user/Daniil%20Elovkov> @ 11:46
am<

http://forum.jetbrains.com/thread/Meta-Programming-System-964?message=Meta-Programming-System-964-1
>

Hi Alan
It seems to be related to http://youtrack.jetbrains.com/issue/MPS-19549
For references to get resolved it should be sufficient to have stub models
for that library (in your case you were offered to create them when you
added it as a library).

I'll be fixing it soon-ish. So far, please try hitting F5 (refresh) if
you're in MPS ide, not in idea plugin.

Just in case, java stub models are java top-level structure (classes,
fields, methods) recovered from class files (possibly in jars) and
represented in models like BaseLanguage classes. They are needed for code
written in MPS to reference those "external" things.

While libraries (that you added in module properties) are needed to
actually compile against that library.

JetBrains Forum | Build #175 (Apr/16/2014 6:53PM) | Feedback<
http://confluence.jetbrains.net/display/JETF/Feedback>





Fabien Campagne, PhD – http://campagnelab.org

Assistant Professor, Dept. of Physiology and Biophysics
Institute for Computational Biomedicine
Associate Director, Biomedical Informatics Core,
Clinical Translational Science Center

Weill Medical College of Cornell University
phone: (646)-962-5613 1305 York Avenue
fax: (646)-962-0383 Box 140
New York, NY 10021

Do you speak next-gen?

See how GobyWeb can help simplify your NGS projects at
http://gobyweb.campagnelab.org

JetBrains Forum | Build #175 (Apr/16/2014 6:53PM) | Feedback<
http://confluence.jetbrains.net/display/JETF/Feedback>





Fabien Campagne, PhD – http://campagnelab.org

Assistant Professor, Dept. of Physiology and Biophysics
Institute for Computational Biomedicine
Associate Director, Biomedical Informatics Core,
Clinical Translational Science Center

Weill Medical College of Cornell University
phone: (646)-962-5613 1305 York Avenue
fax: (646)-962-0383 Box 140
New York, NY 10021

Do you speak next-gen?

See how GobyWeb can help simplify your NGS projects at
http://gobyweb.campagnelab.org

  JetBrains Forum | Build #175 (Apr/16/2014 6:53PM) | Feedback<http://confluence.jetbrains.net/display/JETF/Feedback>




--
Fabien Campagne, PhD – http://campagnelab.org

Assistant Professor,    Dept. of Physiology and Biophysics
          Institute for Computational Biomedicine
Associate Director,      Biomedical Informatics Core,
       Clinical Translational Science Center

Weill Medical College of Cornell University
phone:  (646)-962-5613  1305 York Avenue
fax:    (646)-962-0383  Box 140
New York, NY 10021

Do you speak next-gen?

See how GobyWeb can help simplify your NGS projects at
http://gobyweb.campagnelab.org
0
If the model root is correctly configured, you should see the various packages you imported under Project Tab>solution>all models>stubs. See:
image1
0
I tried removing the JAR and adding it back. This time, the java_classes root is already defined. However, there is still no change to the list of models in the Common tab of the Module Properties.

The module where the JAR is used is a Solution, not a Language. It does not have an "all models" element in the Project tab.
0
Solution or language does not matter in this case, both have stubs. Note that you will only see the stubs item if there is at least one stub to show under it, I think.

Have you placed the jar files you need to import into the solution/language folder, next to the .msd file? Doing so will help you see the jar files immediately in the right panel after you have created the model root. If you don't put them there, you have to use the UI of the right panel to change the directory for the model root.
When you see the file, make sure they are not excluded, but in the state `Model' (top of the right panel toggles).
0
By copying the JAR files into the solution folder and marking them as Models, the references are now valid. Thank you for your help.

  Alan
0

Please sign in to leave a comment.