Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: How do I get the name and path of the running jar file? Date: Tue, 6 Dec 2016 16:07:32 -0500 Organization: A noiseless patient Spider Lines: 19 Message-ID: References: <0564c643-106a-499a-833e-dffe34d1e915@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 6 Dec 2016 21:06:15 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="e65cbc5394c67bc4694f4010530a900f"; logging-data="13409"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wSSO+R9wgOcLq3UZmPn45" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 In-Reply-To: <0564c643-106a-499a-833e-dffe34d1e915@googlegroups.com> Cancel-Lock: sha1:uNjhl05i0lvAPDcA/zGuBxq4jEU= Xref: csiph.com comp.lang.java.programmer:36057 On 12/6/2016 3:41 PM, triciac.1999.p@gmail.com wrote: > I am writing a program that has sound files with type names and numbers like, "win1.wav" and "lose3.wav". I want the program to get the name and path of the running jar file so I can programmatically choose a random sound file of a specified type that is packaged inside the jar file without having to hardcode it myself. Everything I've tried works in Eclipse, but not after it is exported because it doesn't find the name of the jar file, only the path. Is there a way I can get the name AND path of the jar file? Could I search through the jar file packages without using the name and path? Have you tried String classPath = System.getProperty("java.class.path"); ? For me, the class path *is* the path and name of the jar -- I guess it might be more complicated if there are several jars involved, but even then you could split the path on System.getProperty("path.separator") ... and look through the jars one by one. -- esosman@comcast-dot-net.invalid "Nobody ever went broke underestimating the intelligence of the American public." -- HLM (paraphrased)