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
>> 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 - 24 lines]
>
>Andrew T.
Moiristo - 19 Aug 2006 00:02 GMT
> Thank you for your help.
> I have tried your suggestion, but it still does not work since the properties
[quoted text clipped - 10 lines]
>
> It can not find the properties file
The location you are looking for is incorrect. You must not specify the
extension. In your case, it looks for
'com/myjar/resources/log/properties.properties. So, maybe it works when
you change 'name' to "com.myjar.resources.log".
Andrew Thompson - 19 Aug 2006 01:52 GMT
> Thank you for your help.
Please demonstrate your appreciation by not top-posting
in future.
> I have tried your suggestion, but it still does not work since the properties
> file does not locate loosely in the system.
Neither does ....
> > String location = "java/lang/Object.class";
>...It is embbeded inside a jar file.
Which is embedded in the rt.jar.
> Here my situation:
> I have a war file which contains several jar files. The properties file is
> embbeded inside one of the jar file.
A WAR file is a compressed file. If it remains
unexpanded, the class.getResource() will only
find the other 'jar file the properties file is embedded in',
but not the *properties* *file* itself.
Is your WAR file expanded?
Andrew T.
khanhly - 19 Aug 2006 16:25 GMT
>> Thank you for your help.
>
[quoted text clipped - 11 lines]
>
>Which is embedded in the rt.jar.
The properties file
>> Here my situation:
>> I have a war file which contains several jar files. The properties file is
[quoted text clipped - 6 lines]
>
>Is your WAR file expanded?
Yes, Tomcat expands the war file when it starts up
>Andrew T.
Andrew Thompson - 19 Aug 2006 17:08 GMT
...
> >> Here my situation:
> >> I have a war file which contains several jar files. The properties file is
> >> embbeded inside one of the jar file.
..
> >Is your WAR file expanded?
>
> Yes, Tomcat expands the war file when it starts up
OK. AFAIR, servlet containers add jars in the
WEB-INF/lib/ directory to the classpath.
Is your jar inside that directory?
Andrew T.
khanhly - 20 Aug 2006 17:40 GMT
>...
>> >> Here my situation:
[quoted text clipped - 8 lines]
>WEB-INF/lib/ directory to the classpath.
>Is your jar inside that directory?
Yes, after expanded, all the jar files are in the WEB-INF/lib/ dir
When I runs in the Eclipse IDE, it find the properties file OK, but not when
it runs in jar file under Tomcat env.
I have tried several different ways declaring the file path
/com/myjar/log/config.properties
com/myjar/log/config.properties
com/myjar/log/config
com.myjar.log.config
None of those works
>Andrew T.
Thomas Fritsch - 19 Aug 2006 22:16 GMT
> Here my situation:
> I have a war file which contains several jar files. The properties file
[quoted text clipped - 8 lines]
>
> It can not find the properties file
I have no experience with .war files. But I think you'll more have success
with:
String name = "/com/myjar/resources/log.properties";
InputStream st = ...;
[Note the leading '/' !]

Signature
Thomas