Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] (Reading ECore File from ClassPath)
[EMF] [message #946667] Tue, 16 October 2012 11:35 Go to next message
Appasamy Thirugnana is currently offline Appasamy Thirugnana
Messages: 27
Registered: September 2012
Junior Member
Hi Everyone,

I need to load a ecore file from my classpath

ResourceSet resourceSet = new ResourceSetImpl();

 resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put( "*", new EcoreResourceFactoryImpl() );

      final String[] ecores = new String[] { "classpath:models//library.ecore" };

      for( String ecore : ecores ) {
         final Resource res = resourceSet.getResource( URI.createFileURI(ecore ), true );}...


But it is not working.

Can somebody tell me the correct way?

Thanks,
Appasamy
Re: [EMF] [message #946723 is a reply to message #946667] Tue, 16 October 2012 12:46 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 802
Registered: July 2009
Senior Member
hi, Appasamy,

What does "not working" mean? Do you get an exception? If so, what
exception and with what message? Do you get a resource and it just has
no contents? Is this in an Eclipse context where you can see
exceptions logged in the workspace log? There are so many reasons why
this resource might not load as you would expect ...

Cheers,

Christian


On 2012-10-16 11:35:47 +0000, Appasamy Thirugnana said:

> Hi Everyone,
>
> I need to load a ecore file from my classpath
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
> "*", new EcoreResourceFactoryImpl() );
>
> final String[] ecores = new String[] {
> "classpath:models//library.ecore" };
>
> for( String ecore : ecores ) {
> final Resource res = resourceSet.getResource(
> URI.createFileURI(ecore ), true );}...
>
> But it is not working.
>
> Can somebody tell me the correct way?
>
> Thanks,
> Appasamy
Re: [EMF] [message #946727 is a reply to message #946723] Tue, 16 October 2012 12:53 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 750
Registered: July 2009
Senior Member
The following might work:

URI.createURI(FrameworkUtil.getBundle(YourEnclosingClass.class).getEntry("model/library.ecore").toURI().toString(), true)


YourEnclosingClass is the class your code is executing in (in the bundle that contains the library.ecore file).
Re: [EMF] [message #946732 is a reply to message #946723] Tue, 16 October 2012 12:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4097
Registered: July 2009
Senior Member
Hi

classpath URIs are an innovation introduced by MWE; they are unlikely to
work in EMF without following the appropriate MWE initialization orocedures.

Regards

Ed Willink


On 16/10/2012 13:46, Christian W. Damus wrote:
> hi, Appasamy,
>
> What does "not working" mean? Do you get an exception? If so, what
> exception and with what message? Do you get a resource and it just
> has no contents? Is this in an Eclipse context where you can see
> exceptions logged in the workspace log? There are so many reasons why
> this resource might not load as you would expect ...
>
> Cheers,
>
> Christian
>
>
> On 2012-10-16 11:35:47 +0000, Appasamy Thirugnana said:
>
>> Hi Everyone,
>>
>> I need to load a ecore file from my classpath
>>
>> ResourceSet resourceSet = new ResourceSetImpl();
>>
>>
>> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
>> "*", new EcoreResourceFactoryImpl() );
>>
>> final String[] ecores = new String[] {
>> "classpath:models//library.ecore" };
>>
>> for( String ecore : ecores ) {
>> final Resource res = resourceSet.getResource(
>> URI.createFileURI(ecore ), true );}...
>>
>> But it is not working.
>>
>> Can somebody tell me the correct way?
>>
>> Thanks,
>> Appasamy
>
>
Re: [EMF] [message #947541 is a reply to message #946732] Wed, 17 October 2012 07:11 Go to previous messageGo to next message
Appasamy Thirugnana is currently offline Appasamy Thirugnana
Messages: 27
Registered: September 2012
Junior Member
Thanks Christian, Ed, and Erdal.

Meanwhile I am not able to find FrameworkUtil class in my package as I have only EMF Core jars in my project.
Can you please let me know which package I can get this.

Currently I am using below packages:

<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore</artifactId>
<version>2.7.0.v20120127-1122</version>
</dependency>

<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore.xmi</artifactId>
<version>2.7.0.v20120127-1122</version>
</dependency>

<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.common</artifactId>
<version>2.7.0.v20120127-1122</version>
</dependency>



Re: [EMF] [message #947550 is a reply to message #947541] Wed, 17 October 2012 07:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26141
Registered: July 2009
Senior Member
Appasamy,

comments below.

On 17/10/2012 9:11 AM, Appasamy Thirugnana wrote:
> Thanks Christian, Ed, and Erdal.
>
> Meanwhile I am not able to find FrameworkUtil class in my package as I
> have only EMF Core jars in my project.
The context for your question is vague.

Are you trying to run a stand alone application, or is this code
supposed to work running as an Eclipse application?
> Can you please let me know which package I can get this.
>
> Currently I am using below packages:
>
What is this you're showing? I.e., where does this XML come from?
> <dependency>
> <groupId>org.eclipse.emf</groupId>
> <artifactId>org.eclipse.emf.ecore</artifactId>
> <version>2.7.0.v20120127-1122</version>
> </dependency>
>
> <dependency>
> <groupId>org.eclipse.emf</groupId>
> <artifactId>org.eclipse.emf.ecore.xmi</artifactId>
> <version>2.7.0.v20120127-1122</version>
> </dependency>
>
> <dependency>
> <groupId>org.eclipse.emf</groupId>
> <artifactId>org.eclipse.emf.common</artifactId>
> <version>2.7.0.v20120127-1122</version>
> </dependency>
>
>
>
>
Re: [EMF] [message #947795 is a reply to message #947541] Wed, 17 October 2012 12:53 Go to previous message
Erdal Karaca is currently offline Erdal Karaca
Messages: 750
Registered: July 2009
Senior Member
FrameworkUtil is located in the package 'org.osgi.framework' (add org.eclipse.core.runtime or import package org.osgi.framwork).

Thoug, as the other try to tell you: your questions are ambiguous and I am just guessing...


Appasamy Thirugnana wrote on Wed, 17 October 2012 03:11
Thanks Christian, Ed, and Erdal.

Meanwhile I am not able to find FrameworkUtil class in my package as I have only EMF Core jars in my project.
Can you please let me know which package I can get this.

Currently I am using below packages:

<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore</artifactId>
<version>2.7.0.v20120127-1122</version>
</dependency>

<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore.xmi</artifactId>
<version>2.7.0.v20120127-1122</version>
</dependency>

<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.common</artifactId>
<version>2.7.0.v20120127-1122</version>
</dependency>




Previous Topic:[xcore] Obtaining the featureID in op
Next Topic:Re: Couple Graphiti Editor with XText DSL
Goto Forum:
  


Current Time: Fri Oct 24 18:58:51 GMT 2014

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

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