-
1. Re: File Path in EAR..!!!
jaikiran Jul 12, 2006 6:21 AM (in response to ashudagr8)Try this out:
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("conf/config.xml");
-
2. Re: File Path in EAR..!!!
ashudagr8 Jul 12, 2006 6:48 AM (in response to ashudagr8)Thanks for reply..
Atually i have a third party method that takes as input object of type
java.io.Reader.
So, after using FileReader in = new FileReader(filelocation) i have to pass
the "in" object to this method...
So i am afraid i cannot use getResourceAsStream()...
How can i get through this problem? -
3. Re: File Path in EAR..!!!
jaikiran Jul 12, 2006 7:12 AM (in response to ashudagr8)third party method that takes as input object of type java.io.Reader
This is what you can do:InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("conf/config.xml"); InputStreamReader inputStreamReader = new InputStreamReader(inputStream) ; thidPartyLib.someAPI(inputStreamReader);
Have a look at the InputStreamReader:
http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStreamReader.html -
4. Re: File Path in EAR..!!!
ashudagr8 Jul 12, 2006 7:53 AM (in response to ashudagr8)Thanks for Patience ..!!!
but things are still not working... i am prompted with the exception like
java.lang.NullPointerException
at java.io.Reader.(Unknown Source)
at java.io.InputStreamReader.(Unknown Source)
Any help ???
-Ashu -
5. Re: File Path in EAR..!!!
jaikiran Jul 12, 2006 8:26 AM (in response to ashudagr8)java.lang.NullPointerException
Looks like the inputStream was null. Which means that the xml file was not found by the getResourceAsStream method. Try out the following, add aSystem.out.println("Inputstream is: " + inputStream);
after the call to getResourceAsStream method. See if it prints null. Also, execute the following command and post the output:jar -tf yourApp.ear
or if your application is a warjar -tf yourApp.war
-
6. Re: File Path in EAR..!!!
ashudagr8 Jul 12, 2006 11:03 PM (in response to ashudagr8)Here are the output's
InputStream = null
jar -tf myApp.war gives
META-INF/
META-INF/MANIFEST.MF
META-INF/application.xml
WEB-INF/
WEB-INF/jboss-web.xml
WEB-INF/web.xml
WEB-INF/classes/
WEB-INF/classes/sss/
WEB-INF/classes/sss/tt/
WEB-INF/classes/sss/tt/rt/
WEB-INF/classes/sss/tt/rt/FT.class
WEB-INF/classes/sss/tt/xd/
WEB-INF/classes/sss/tt/xd/P.class
WEB-INF/classes/sss/tt/xd/Tt.class
WEB-INF/classes/sss/tt/xd/TD.class
WEB-INF/classes/sss/tt/xd/TS.class
WEB-INF/conf/
WEB-INF/conf/tm.xml
WEB-INF/Data/
WEB-INF/Data/Fc.xml
WEB-INF/lib/
WEB-INF/lib/ct-1.0.1-xml.jar
WEB-INF/lib/cus-1.7.2.jar
I am trying to read /conf/tm.xml and /Data/Fc.xml in class TD.class..
Any Suggestions ? -
7. Re: File Path in EAR..!!!
jaikiran Jul 13, 2006 2:30 AM (in response to ashudagr8)WEB-INF/conf/tm.xml
This means that your tm.xml file is in youWar.war/WEB-INF/conf directory. So your code should look like:InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("WEB-INF/conf/tm.xml"); InputStreamReader inputStreamReader = new InputStreamReader(inputStream) ; thidPartyLib.someAPI(inputStreamReader);
-
8. Re: File Path in EAR..!!!
ashudagr8 Jul 13, 2006 5:13 AM (in response to ashudagr8)Thanks a lot things are working now.. !!!