Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Loading resource from jar file(Loading resource from jar file with relative url)
Loading resource from jar file [message #997543] Tue, 08 January 2013 08:50 Go to next message
Pradeep Badiger is currently offline Pradeep BadigerFriend
Messages: 53
Registered: November 2012
Member

Hi,

I am trying to load a resource (*.ecore) file within a jar file with relative location to jar file.

Here is an example:

jar:file:/../../com.example.model.jar!/model/com.example.basemodel.ecore

But loading this file as a resource throws FileNotFoundException for the jar file.

I have cross checked the path of jar file and the path of ecore inside it.

Providing an absolute path to the jar file works fine.

Can anyone help me get this working with relative path?

thanks,
Pradeep
Re: Loading resource from jar file [message #997658 is a reply to message #997543] Tue, 08 January 2013 09:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
Pradeep,


Try archive: and be sure the thing after the file: is really an archive
that exists. I assume you don't really have file:/.. as part of the
path; that makes little sand will depend on what your current
directory. Use File.getAbsolutePath to create this part of your URI and
be sure that File.exists is true.


On 08/01/2013 9:50 AM, Pradeep Badiger wrote:
>
> Hi,
>
> I am trying to load a resource (*.ecore) file within a jar file with
> relative location to jar file.
>
> Here is an example:
>
> jar:file:/../../com.example.model.jar!/model/com.example.basemodel.ecore
>
> But loading this file as a resource throws FileNotFoundException for
> the jar file.
>
> I have cross checked the path of jar file and the path of ecore inside
> it.
>
> Providing an absolute path to the jar file works fine.
>
> Can anyone help me get this working with relative path?
>
> thanks,
> Pradeep
Re: Loading resource from jar file [message #997791 is a reply to message #997658] Tue, 08 January 2013 18:51 Go to previous messageGo to next message
Pradeep Badiger is currently offline Pradeep BadigerFriend
Messages: 53
Registered: November 2012
Member
Hi Ed,

I am trying it on the EMF editor (Load Resource dialog provided by the EMF editor). I dont have the option to use any API as you mentioned.

I was wondering, if its really possible to have relative path for the resource within a jar file.

I have the jar file containing a resource placed relatively to the ecore file where i am trying to load.

Please let me know if I have clearly defined my problem.

Let me know your thoughts.

thanks,
Pradeep
Re: Loading resource from jar file [message #997982 is a reply to message #997791] Wed, 09 January 2013 05:34 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
Pradeep,

No, as I said, if it works at all, its interpreted relative to the
current directory of the process, and what's that for the running IDE
and how do you know nothing changes it? So use an absolute path. If
it's in the workspace you could use
jar:platform:/resource/<project>/<path>/<jar>!/<path-in-jar>.

On 08/01/2013 7:51 PM, Pradeep Badiger wrote:
> Hi Ed,
>
> I am trying it on the EMF editor (Load Resource dialog provided by the
> EMF editor). I dont have the option to use any API as you mentioned.
>
> I was wondering, if its really possible to have relative path for the
> resource within a jar file.
>
> I have the jar file containing a resource placed relatively to the
> ecore file where i am trying to load.
> Please let me know if I have clearly defined my problem.
>
> Let me know your thoughts.
>
> thanks,
> Pradeep
Re: Loading resource from jar file [message #998075 is a reply to message #997982] Wed, 09 January 2013 10:27 Go to previous messageGo to next message
Pradeep Badiger is currently offline Pradeep BadigerFriend
Messages: 53
Registered: November 2012
Member
Thanks Ed.

I kept the jar file in the project where it has to be loaded and used your approach to load the resource.

I observered one thing using this approach. If i make any changes in the loaded resource and copy the jar file into the path where it is referenced, and if i open the file referencing this resource, i dont see changes that i made in the loaded resource.

I checked the Temp folder where it had created a cache for this loaded jar file and it is not getting updated, till i close the ide and reopen it again.

Do you know how we can avoid a cache for such resource?

thanks,
Pradeep
Re: Loading resource from jar file [message #998097 is a reply to message #998075] Wed, 09 January 2013 11:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
Pradeep,

Comments below.

On 09/01/2013 11:27 AM, Pradeep Badiger wrote:
> Thanks Ed.
>
> I kept the jar file in the project where it has to be loaded and used
> your approach to load the resource.
>
> I observered one thing using this approach. If i make any changes in
> the loaded resource and copy the jar file into the path where it is
> referenced,
I don't follow... Where was the jar before you referenced it? What
resource is loaded? What are you changing?
> and if i open the file referencing this resource,
Which resource?
> i dont see changes that i made in the loaded resource.
Where did you make the changes? Have you saved any changes?
>
> I checked the Temp folder where it had created a cache for this loaded
> jar file
Why are you doing that?
> and it is not getting updated, till i close the ide and reopen it again.
Hmmm. Maybe something to do with using JarFile...
>
> Do you know how we can avoid a cache for such resource?
I'm not sure I understand the problem. Maybe you can create a
self-contained test case and open a bugzilla so I can have a look at that?
>
> thanks,
> Pradeep
Re: Loading resource from jar file [message #998494 is a reply to message #998097] Thu, 10 January 2013 05:23 Go to previous messageGo to next message
Pradeep Badiger is currently offline Pradeep BadigerFriend
Messages: 53
Registered: November 2012
Member
Steps to reproduce the issue
1. Run "mvn clean install" on com.example.basemodel project
2. Run "mvn clean" on com.example.model project. This will copy the com.example.basemodel.jar to the target folder of com.example.model project.
3. Load resource from model.ecore within com.example.model project.
using - jar:platform:/resource/com.example.model/target/com.example.basemodel.jar!/model/basemodel.ecore
4. Now check the class name within the loaded resource. It should have "Person" class within the "basemodel" package.
5. Rename the "Person" class to "NewPerson" within basemodel.ecore in com.example.basemodel project.
6. Repeat steps 1, 2 and 3.
7. Now if you check the class within the loaded resource, the class name still remains as "Person", whereas it should have been "NewPerson".
8. If IDE is restarted and step 3 is repeated, then one can see the changes made in the basemodel.ecore which is loaded in model.ecore

In my workspace, i will never have the com.example.basemodel project to build. I will copy it to my com.example.model project and add the reference.

[Updated on: Thu, 10 January 2013 06:01]

Report message to a moderator

Re: Loading resource from jar file [message #998534 is a reply to message #998494] Thu, 10 January 2013 07:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26215
Registered: July 2009
Senior Member
Pradeep,

Comments below.

On 10/01/2013 6:23 AM, Pradeep Badiger wrote:
> Steps to reproduce the issue
> 1. Run "mvn clean install" on com.example.basemodel project
What's mvn?
> 2. Run "mvn clean" on com.example.model project. This will copy the com.example.basemodel.jar to the target folder of com.example.model project.
Why would you need to do such a thing? I'd expect they're plugin
projects with a proper dependency...
> 3. Load resource from model.ecore within com.example.model project.
> using - jar:platform:/resource/com.example.model/target/com.example.basemodel.jar!/model/basemodel.ecore
If I recall correctly, a jar: URL will open a JarFile and will keep it
open for the lifetime of the JVM...

Try using archive: instead.
> 4. Now check the class name within the loaded resource. It should have "Person" class within the "basemodel" package.
> 5. Rename the "Person" class to "NewPerson" within com.example.basemodel project.
> 6. Repeat steps 1, 2 and 3.
> 7. Now if you check the class within the loaded resource, the class name still remains as "Person", whereas it should have been "NewPerson".
This seems to that step 2 didn't actually update the jar, which makes
sense if the jar is locked because there's an open stream on it. Have
you confirmed the jar really is updated by your step 2? But then again,
the jar: URL itself might keep an in memory copy... Not sure, but a jar:
URI is handled as just a URL, so whatever Java does for a URL with jar
protocol, that's beyond my control... Try archive: instead; it has the
same semantics, but is implemented to load/save using ZipFile/ZipStream.
> 8. If IDE is restarted and then if step 3 is repeated, then one can see the changes made in the basemodel.ecore which is loaded in model.ecore
>
> In my workspace, i will never have the com.example.basemodel project to build. I will copy it to my com.example.model project and add the reference.
Do you generate code from these models?
Re: Loading resource from jar file [message #998560 is a reply to message #998534] Thu, 10 January 2013 08:37 Go to previous message
Pradeep Badiger is currently offline Pradeep BadigerFriend
Messages: 53
Registered: November 2012
Member
Hi Ed,

First two steps are for just to quickly get started on the projects.

I used archive: now instead of jar: and it is working fine for me.

I would be generating java code from the model files. I am using Texo for generating code. But I see that using the archive: doesnt work when i generate code having reference to other model file. Whereas, using jar: works fine.

I will have to check Texo's implementation and raise a question on TEXO forum.

thanks for your help.

regards,
Pradeep

Previous Topic:[Xcore]
Next Topic:EMF and SOAP - how?
Goto Forum:
  


Current Time: Mon Nov 24 04:21:55 GMT 2014

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

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