Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Call a jar library function from generated code in src-gen
Call a jar library function from generated code in src-gen [message #1698982] Fri, 19 June 2015 09:44 Go to next message
sam narayan is currently offline sam narayanFriend
Messages: 11
Registered: June 2015
Junior Member
Hello all,

Am using Eclipse 3.7.2 and XText 2.3.0. I am writing a simple Xtext grammar with commands. In the Xtend code generator class "org.xtext.example.mydsl.generator/MyDslGenerator.xtend" file, I have added code to instantiate another class and use its methods.

When I edit the Xtext file, the "src-gen" folder is created, however the class that I have added is not resolved. When I add the external jar to the project as a referenced library, then the generated code finds the class and runs without errors.

The use case is that , when a user creates any new java project, and edits a"xxxx .mydsl" file, the code which is generated in the src-gen shall call the library functions, in the jar when executed.

I do not know how to add this jar referenced library to each java project that is created, even before code generation, so the generated code can find and resolve the classes.

Many thanks for your time,






Re: Call a jar library function from generated code in src-gen [message #1698983 is a reply to message #1698982] Fri, 19 June 2015 09:52 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

You could register an IXtextBuilderParticipant in the UI project that checks the built IProject if it is a valid Java project and does not have the library on the classpath. Then add the missing library to the IJavaProject with means of the JDT API.

Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Call a jar library function from generated code in src-gen [message #1699357 is a reply to message #1698983] Tue, 23 June 2015 14:50 Go to previous message
sam narayan is currently offline sam narayanFriend
Messages: 11
Registered: June 2015
Junior Member
Thanks for your time and reply Karsten.

In the UI project (org.xtext.example.mydsl.ui), I see the AbstractMyDslUiModule class; is this were we register the IXtextBuilderParticipant? Could you show me with a small code snippet?

To find the active project (IJavaProject), I do it this way:

IFileEditorInput input = (IFileEditorInput)editorPart.getEditorInput() ;
IFile file = input.getFile();
IProject activeProject = file.getProject();
if (activeProject.hasNature(JavaCore.NATURE_ID)) {
 targetProject = JavaCore.create(activeProject);
........//add library to classpath
}


Once the "targetProject" is found, I could add the missing library to a classpath container using the JDT Api as you mentioned; is this a right approach?

Many thanks
Previous Topic:EcoreUtil.equals is not returning the value properly
Next Topic:using common terminal names as keywords
Goto Forum:
  


Current Time: Tue Mar 19 03:51:27 GMT 2024

Powered by FUDForum. Page generated in 0.02451 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top