Article View: borland.public.jbuilder.java.language
Article #269Re: location of jar file
From: Gillmer J. Derge [TeamB]
Date: Mon, 23 Oct 2006 02:02
Date: Mon, 23 Oct 2006 02:02
21 lines
1868 bytes
1868 bytes
Oliver wrote:
> i have a question concerning the location of the jar file.
> In Delphi there is the application object, and the property
> ExeName gives the location of the exe. In Java there is no
> application object. But i still would like to know where the jar
> file is located.
String myClassName = MyClass.getName();
String myClassFileName = myClassName.replace('.', '/') + ".class";
URL whereAmI = MyClass.class.getResource(myClassFileName);
Fix any syntax errors. I've used this general approach before, but I
haven't actually compiled or tested the exact code shown above.
If the class is in a JAR file, this will be a JAR URL. See the
documentation on java.net.JarURLConnection for more details. If the
class file comes from somewhere else (a directory with class files, a
network URL, etc.) then you would need to handle that differently.
--
Gillmer J. Derge [TeamB]
Technical Details
Message-ID:
<453c22ae$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4538af7b$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,f288e71066ccfddf X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Sun, 22 Oct 2006 22:02:23 -0400 From: "Gillmer J. Derge [TeamB]" <spam@gillmerderge.com> User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: location of jar file References: <4538af7b$1@newsgroups.borland.com> In-Reply-To: <4538af7b$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.149.56.198 Message-ID: <453c22ae$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1161568942 24.149.56.198 (22 Oct 2006 19:02:22 -0700) Lines: 21 Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail