Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtend code generation: include library
Xtend code generation: include library [message #1804551] Thu, 28 March 2019 16:45 Go to next message
Niels Heltner is currently offline Niels HeltnerFriend
Messages: 6
Registered: March 2019
Junior Member
Hello,

I am using Xtend to generate Java code based on a program written in my DSL. Alongside this generated Java code, I would like to include a library (two Java files I have already written, that won't change based on the DSL program). What is the best way to include such a library ?

I know it's possible to simply copy-paste the two Java files into an Xtend template and generate the files from there, but I would rather programatically copy the files.

Thanks in advance.

[Updated on: Thu, 28 March 2019 19:05]

Report message to a moderator

Re: Xtend code generation: include library [message #1804567 is a reply to message #1804551] Thu, 28 March 2019 18:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
hi maybe you are looking for something like http://blog.vogella.com/2010/07/06/reading-resources-from-plugin/

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Xtend code generation: include library [message #1804568 is a reply to message #1804567] Thu, 28 March 2019 19:04 Go to previous messageGo to next message
Niels Heltner is currently offline Niels HeltnerFriend
Messages: 6
Registered: March 2019
Junior Member
I can't seem to get that working in Xtend. It doesn't recognize Bundle or Platform.

Re: Xtend code generation: include library [message #1804569 is a reply to message #1804568] Thu, 28 March 2019 19:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
well the problem is that is not available outside of eclipse.
the runtime module is meant to work from standalone mode as well where no plugins exist

=> you could create a Service IDoSomething
=> implement it in runtime with a impl that throws an illegalstate (or does read the file from classpath)
=> implement it in ui by using the code from above
=> add bindings to both runtime and ui
=> inject service to generator and call it from there


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Xtend code generation: include library [message #1804573 is a reply to message #1804569] Thu, 28 March 2019 20:08 Go to previous messageGo to next message
Niels Heltner is currently offline Niels HeltnerFriend
Messages: 6
Registered: March 2019
Junior Member
I'll rephrase my question: is it possible to access files in the project where my xtext grammar and xtend generator are, from the project in a new Eclipse runtime, where I write programs in my DSL?
Re: Xtend code generation: include library [message #1804574 is a reply to message #1804573] Thu, 28 March 2019 20:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
what do you mean by "access files"
and what do you mean by "access from the project"

if e.g. you want to create a java library and your model project can be a java project
you can make the model project a plugin project,
create a library plugin and add it to the dependencies of the model project.

or you create a custom classpath container as XtendContainerInitializerdoes it for xtend
(you can see how that works if you
- create a java project
- create a xtend file
- it will complain about missing library
- there is a quickfx to add it


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Thu, 28 March 2019 20:27]

Report message to a moderator

Re: Xtend code generation: include library [message #1804578 is a reply to message #1804551] Thu, 28 March 2019 21:53 Go to previous message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Quote:
I'll rephrase my question: is it possible to access files in the project where my xtext grammar and xtend generator are, from the project in a new Eclipse runtime, where I write programs in my DSL?


Nothing is impossible, but this approach does not make sense. Put your library into a library project and reference the library like you would do for any other Java library. If your target project is a plugin project, the library should also be a plugin project and use plugin dependencies. If the library is plain Java, build a Jar and use it as a referenced library.

The target project where the code is generated to is "just" a Java project, so think that you need a library in a Java project. That's it.
Previous Topic:[Language]ProposalProvider for generic IDE (VS-Code)
Next Topic:Update label of search page
Goto Forum:
  


Current Time: Mon Dec 02 11:21:46 GMT 2024

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

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

Back to the top