Just seems cleaner to me that's all. I'm there are cases where both methods
break down anyhow (make your own class on the fly with BCEL and load it).

--DD

PS: You still assume the class is coming from a JAR. I'd have to check
myClassURL to see if it's file: based, http: based, jar: based, etc... And
you'd have to deal with inner classes in a.B$C, etc... It gets complex.

-----Original Message-----
From: Gordon Tyler [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, December 05, 2002 4:55 PM
To: Ant Users List
Subject: Re: [OT] getting name of launch jar

Dominique Devienne wrote:
> Which kind of breaks down if the class is not loaded from the System class
> loader, but a child loader of it (or a child loader of a parent of the
> system loader), and if the class is loaded from a classes/ directory.

Indeed. That wasn't an issue for our particular case. The following may 
work for those situations:

String className = MyClass.class.getName();
URL myClassUrl = MyClass.class.getResource("/" + className.replace('.', 
'/') + ".class");
URL jarUrl = 
((JarURLConnection)myClassUrl.openConnection()).getJarFileURL();

I think.

> Nevertheless, I don't think
> it's the recommended way to do it. --DD

Why not? What recommends the getProtectionDomain method over this one?

Ciao,
Gordon

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to