Xtend code generation: include library [message #1804551] |
Thu, 28 March 2019 16:45 |
Niels Heltner 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 #1804569 is a reply to message #1804568] |
Thu, 28 March 2019 19:07 |
|
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 #1804574 is a reply to message #1804573] |
Thu, 28 March 2019 20:09 |
|
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 |
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.05190 seconds