Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with classpath uri imports
Problem with classpath uri imports [message #775289] Thu, 05 January 2012 18:20 Go to next message
Thomas Ponweiser is currently offline Thomas PonweiserFriend
Messages: 9
Registered: January 2012
Junior Member
Hello again,

In order to automatically import some built-in definitions for my DSL (see my original problem), I've been trying to follow the advise of Meinte Boersma to use a custom GlobalScopeProvider and overwrite the getImportedUris() method as described in the Itemis blog.

It states that I should create an URI for the resourcefile containing the needed definitions with:
URI.createURI("classpath:/the/library/package/defaults.mydsl")

My resourcefile is located in the "src" folder of my Xtext main project in the java package "ao.explorer.dsl" and is named "builtin.aodsl".

I guess that my adapted code should then look like this:
URI.createURI("classpath:/ao/explorer/dsl/builtin.aodsl")

Anyway, my resourcfile is not found by the Xtext framework but is definitely in the classpath (it can be opened using ClassLoader.getResourceAsStream()). I guess that it simply has to be made visible somehow. How do I do that?

[Updated on: Tue, 10 January 2012 10:34]

Report message to a moderator

Re: Problem with classpath uri imports [message #775306 is a reply to message #775289] Thu, 05 January 2012 18:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

about which classpath are we talking? the one of the model project or the one with your dsl stuff?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem with classpath uri imports [message #776126 is a reply to message #775289] Sat, 07 January 2012 15:12 Go to previous messageGo to next message
Thomas Ponweiser is currently offline Thomas PonweiserFriend
Messages: 9
Registered: January 2012
Junior Member
I launched a new Eclipse instance and tested the editor generated by Xtext.

In my getImportedUris() method, I additionally read the contents of my resourcefile with ClassLoader.getResourceAsStream() and printed them out on standard output, which worked.

Obviousely the URI returned by this method cannot be resolved by the Xtext framework.

Debugging the code does not give me a clue on what is going wrong. I do not get any error or warning messages even if I'm returning a complete erroneous URI like "classpath:/asdf/xxx".

On the other hand, the importing mechanism works fine, when referencing another DSL file in the Eclipse project using an explicit import and a relative URI. But also here, as soon as I'm trying to use "classpath:/" URIs in my import statement, the editor indicates an error (The URI cannot be resolved - I turned on the check for imported URIs).

Do I have to activate a special Resolver for "classpath:/" URIs?
Re: Problem with classpath uri imports [message #777344 is a reply to message #776126] Tue, 10 January 2012 10:06 Go to previous messageGo to next message
Thomas Ponweiser is currently offline Thomas PonweiserFriend
Messages: 9
Registered: January 2012
Junior Member
Finally I found a workaround for my problem:

Instead of using a "classpath:/" URI I did the following:
URL url = this.getClass().getClassLoader().getResource("/ao/explorer/dsl/builtin.aodsl");
URI uri = URI.createURI(url.toURI().toString());

This produces an URI of the form
bundleresource://552.fwk9948533/ao/explorer/dsl/builtin.aodsl

Anyway - does anyone know why "classpath:/" URIs do not work for me? Is this a bug?
Re: Problem with classpath uri imports [message #798418 is a reply to message #775289] Tue, 14 February 2012 17:14 Go to previous message
Peter Miklos is currently offline Peter MiklosFriend
Messages: 1
Registered: February 2012
Junior Member
Hi,

Using URI.createURI("platform:/plugin/<your-plugin-id>/resources/builtin.dsl") worked for me. All you have to do is to add the 'resources' folder to the plugin classpath.

-Peter
Previous Topic:[Xtext 2.3] Where is bundle "org.eclipse.xtext.xtend2.lib"
Next Topic:Using generated Antlr parser from plain java app
Goto Forum:
  


Current Time: Fri Mar 29 09:41:10 GMT 2024

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

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

Back to the top