Loading resource from jar file [message #997543] |
Tue, 08 January 2013 03:50  |
Eclipse User |
|
|
|
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 #997982 is a reply to message #997791] |
Wed, 09 January 2013 00:34   |
Eclipse User |
|
|
|
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 #998534 is a reply to message #998494] |
Thu, 10 January 2013 02:25   |
Eclipse User |
|
|
|
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 03:37  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.05638 seconds