We use the following trick:

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

Ciao,
Gordon

Laurie Harper wrote:
(I know this is off-topic for this list, but I need to find an answer fast or change approach so I was hoping someone might be able to give me a pointer!)

I've got an application which is packaged as a single jar, launched by 'java -jar myapp.jar'. The problem is I need to be able to get the path and file-name of the jar file.

Does anyone know if there is a way to do this?

Thanks,

L.
--
Gordon Tyler
Software Developer, R&D
Sitraka (now part of Quest Software)
"Performance is Mission Critical"


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

Reply via email to