Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Any way to "reduce" a "jar-URL" to an actual path?
Any way to "reduce" a "jar-URL" to an actual path? [message #329359] Fri, 20 June 2008 21:18 Go to next message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
R3.3; WinXP

We have a clunky old 3rd-party bit of code to which we must supply, in
the form of Windows full-paths, concatenated with ";", the actual
class-paths of all code and jars in some set. Thanks to an earlier post
("How to compute classpath from bundle?") by Jeff Pilgrim (whose email
address is no longer valid, alas), I have some code that will extract
from the Platform and the Bundle API a collection of URL's. So far so
good. Here is an example list:

jar:file:C:\<my-Eclipse-install>\eclipse\plugins\org.eclipse.ui_3.3.0.I20070614-0800.jar!/
jar:file:C:\<my-Eclipse-install>\eclipse\plugins\org.eclipse.swt_3.3.0.v3346.jar!/
jar:file:C:\<my-Eclipse-install> \eclipse\plugins\org.eclipse.jface_3.3.0.I20070606-0010.jar! /
jar:file:C:\<my-Eclipse-install> \eclipse\plugins\org.eclipse.core.commands_3.3.0.I20070605-0 010.jar!/

where I have printed the URL values using URL.toString().

The problem is -- how to convert such a "jar-URL" to a string? Our
clunky old 3rd-party code would want the list to look like this:

C:\<my-Eclipse-install>\eclipse\plugins\org.eclipse.ui_3.3.0.I20070614-0800.jar
C:\<my-Eclipse-install>\eclipse\plugins\org.eclipse.swt_3.3.0.v3346.jar
C:\<my-Eclipse-install>\eclipse\plugins\org.eclipse.jface_3.3.0.I20070606-0010.jar
C:\<my-Eclipse-install> \eclipse\plugins\org.eclipse.core.commands_3.3.0.I20070605-0 010.jar

Now, I can (and probably soon will have to) build my own little parser,
whose input would be URL.toString(), but that's of course fragile and
bug-prone.

I'd prefer it if there were a Platform of FileLocator method that took
as input one of the URL's and gave me the desired String as output. But
FileLocator.resolve(URL) simply does not work (it does other nice
things), and in fact the URL's above are *ALREADY* the output of
FileLocator.resolve(). I've also tried FileLocator.toFileURL(), which
seems to simply return the same URL, in this case.

So what is to be done?

TIA,
Paul
Re: Any way to "reduce" a "jar-URL" to an actual path? [message #329404 is a reply to message #329359] Mon, 23 June 2008 12:43 Go to previous messageGo to next message
Owen Rees is currently offline Owen ReesFriend
Messages: 41
Registered: July 2009
Member
"Paul Th. Keyser" <rolarenfan@earthlink.net> writes:

[...]
> jar:file:C:\<my-Eclipse-install> \eclipse\plugins\org.eclipse.core.commands_3.3.0.I20070605-0 010.jar!/
>
> where I have printed the URL values using URL.toString().
>
> The problem is -- how to convert such a "jar-URL" to a string? Our
> clunky old 3rd-party code would want the list to look like this:
>
[...]
> C:\<my-Eclipse-install> \eclipse\plugins\org.eclipse.core.commands_3.3.0.I20070605-0 010.jar

Converting to a String is not the problem, what you are aiming for is
an absolute file path (as a string).

The jar: form of URL is a Java thing, not specific to Eclipse. You
probably should look at the documentation for
java.net.JarURLConnection and take it from there.

--
Owen Rees; speaking personally, and not on behalf of HP.
========================================================
Hewlett-Packard Limited. Registered No: 690597 England
Registered Office: Cain Road, Bracknell, Berks RG12 1HN
Re: Any way to "reduce" a "jar-URL" to an actual path? [message #329423 is a reply to message #329359] Mon, 23 June 2008 17:33 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

FileLocator.toFileURL(*) is the method that should be used in your case.
It will convert any platform: URLs into file: URLs ... it might be
that passing in the jar: URLs is confusing it, and they should be the
platform: URLs

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Any way to "reduce" a "jar-URL" to an actual path? [message #329428 is a reply to message #329423] Mon, 23 June 2008 21:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Paul,

Isn't there a danger that the jar will be unzipped when that might not
be a desired side-effect? Of course you're right that if it has
platform: or bundleentry: you'd need a more general approach...


Paul Webster wrote:
> FileLocator.toFileURL(*) is the method that should be used in your
> case. It will convert any platform: URLs into file: URLs ... it might
> be that passing in the jar: URLs is confusing it, and they should be
> the platform: URLs
>
> PW
>
Re: Any way to "reduce" a "jar-URL" to an actual path? [message #329435 is a reply to message #329404] Tue, 24 June 2008 09:01 Go to previous messageGo to next message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
Owen Rees wrote:
> "Paul Th. Keyser" <rolarenfan@earthlink.net> writes:
>
> [...]
>> jar:file:C:\<my-Eclipse-install> \eclipse\plugins\org.eclipse.core.commands_3.3.0.I20070605-0 010.jar!/
>>
>> where I have printed the URL values using URL.toString().
>>
>> The problem is -- how to convert such a "jar-URL" to a string? Our
>> clunky old 3rd-party code would want the list to look like this:
>>
> [...]
>> C:\<my-Eclipse-install> \eclipse\plugins\org.eclipse.core.commands_3.3.0.I20070605-0 010.jar
>
> Converting to a String is not the problem, what you are aiming for is
> an absolute file path (as a string).
>
> The jar: form of URL is a Java thing, not specific to Eclipse. You
> probably should look at the documentation for
> java.net.JarURLConnection and take it from there.
>
Right, as you say, String per se is not the problem (e.g., toString()
gets me a String), and what I want is that absolute-file-path.

Glad to know that the "jar:"-URL is standard Java; & thanks for the
pointer to
http://java.sun.com/javase/6/docs/api/java/net/JarURLConnect ion.html
which I did not know about; those docs emphasize that the 3rd-party code
we are struggling with is truly clunky, since JarURLConnection seems to
be intended to be used to work with the jar without having to "reduce"
to an absolute file-path.

-Paul
Re: Any way to "reduce" a "jar-URL" to an actual path? [message #329436 is a reply to message #329428] Tue, 24 June 2008 09:12 Go to previous message
Paul E. Keyser is currently offline Paul E. KeyserFriend
Messages: 878
Registered: July 2009
Senior Member
Ed Merks wrote:
> Paul,
>
> Isn't there a danger that the jar will be unzipped when that might not
> be a desired side-effect? Of course you're right that if it has
> platform: or bundleentry: you'd need a more general approach...
>
>
> Paul Webster wrote:
>> FileLocator.toFileURL(*) is the method that should be used in your
>> case. It will convert any platform: URLs into file: URLs ... it might
>> be that passing in the jar: URLs is confusing it, and they should be
>> the platform: URLs
>>
>> PW
>>
Well, I started with what I took to be a platform URL (obtained from
"ManifestElement"), and used FileLocator.resolve(), which gave me the
"jar:"-URL's; if I try toFileURL(), I get as follows:

bundleentry://78/
mapped by FileLocator.resolve() =>
jar:file:C:\<my-eclipse-install>\eclipse\plugins\org.eclipse.ui_3.3.0.I20070614-0800.jar!/
mapped by FileLocator.toFileURL() =>
file:/C:/<my-eclipse-install> /eclipse/workspace/.metadata/.plugins/org.eclipse.pde.core/u dat.product/org.eclipse.osgi/bundles/78/1/.cp/

So it looks to me like the toFileURL() is unzipping (or anyway copying)
the jar into a sort of work-area defined and used by Eclipse.

-Paul
Previous Topic:Setting content types on a per-project basis
Next Topic:New plugin for Run>Run...
Goto Forum:
  


Current Time: Sat Jul 27 20:24:23 GMT 2024

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

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

Back to the top