Re: Open a file embbeded in a jar file
Thank you for your help.
I have tried your suggestion, but it still does not work since the properties
file does not locate loosely in the system. It is embbeded inside a jar file.
Here my situation:
I have a war file which contains several jar files. The properties file is
embbeded inside one of the jar file.
I tried to load that properties file and I have tried this way
String name = "com.myjar.resources.log.properties";
InputStream st = ClassLoader.getSystemClassLoader().getResourceAsStream
(name);
It can not find the properties file
Andrew Thompson wrote:
I need to get data out from a text/properties file which embedded inside a
jar file. Here is the sample code
[quoted text clipped - 5 lines]
Is there the way that I can open a file embedded inside a jar file?
Sure. Here is an example of finding the 'Object'
class by it's name - note
a) the '/'s
b) the firstmost '/' of the successful string.
<sscce>
class GetResourceTest {
public static void main(String args[]) {
Object o = new Object();
String location = "java/lang/Object.class";
java.net.URL url = o.getClass().getResource(
location);
System.out.println( url );
url = o.getClass().getResource(
"/" + location);
System.out.println( url );
}
}</sscce>
HTH
Andrew T.
--
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200608/1