Hello,
my deployment environment is Sun Java system, JBoss, Websphere, Weblogic as the application is inhouse tested on all possible App servers.
In certain (POJO)class, in the EAR, I want to create a 'FILE' object by passing relative path of a folder containing XML files to the FILE CONSTRUCTOR.
Say ...
File myFile = new File("/config/resources/xml");
File[] myFileArray = myFile.listFiles();
....work on the array and parse each file using XML parser.
The issue, I am facing is, when I pass the relative folder path, it does not get resolved and always leads to NULLPOINTER.
Can anybody help, how to resolve this thing.I was wondering if theres any API to access the
EAR deployment directory (Win/*nix) independant and append the latter path it.
Say...
${app.Dep.Dir}/config/resources/xml
Thanks for your Help !
VJ
-
How to Read files in relative folder deployed in EAR (HELP!) (5 messages)
- Posted by: VIJAY KHANNA
- Posted on: February 17 2005 22:52 EST
Threaded Messages (5)
- How to Read files in relative folder deployed in EAR (HELP!) by Kris Huggins on February 18 2005 11:09 EST
- How to Read files in relative folder deployed in EAR (HELP!) by Randall Maier on February 18 2005 15:04 EST
- How to Read files in relative folder deployed in EAR (HELP!) by VIJAY KHANNA on February 18 2005 23:50 EST
- Thanks ! by VIJAY KHANNA on February 19 2005 01:09 EST
- How to Read files in relative folder deployed in EAR (HELP!) by VIJAY KHANNA on February 18 2005 23:50 EST
- Re: How to Read files in relative folder deployed in EAR (HELP!) by krishna k on June 26 2007 10:10 EDT
-
How to Read files in relative folder deployed in EAR (HELP!)[ Go to top ]
- Posted by: Kris Huggins
- Posted on: February 18 2005 11:09 EST
- in response to VIJAY KHANNA
I'm no expert on this and am not pretending to know the answer.
Look into Class.getResourceAsStream(...)
This is used, for example, to load configuration files that are in the classpath. I've only ever used this with config files outside of jar/ear files, therefore, I'm not sure of the implication of your file being in an ear file and I'm not sure of the implication of your file being in a subdirectory of your classpath and not directly in your classpath.
Hope that helps.
As a follow up, I'm confused why your xml files are in the ear file. These types of files are usually used as configuration files and the permise behind these is that you can change them without recompiling or rebuilding your ear. Therefore, these files are usually in the directory along side the ear file and therefore are in the classpath (and can use Class.getResourceAsStream()). If you are going to requiere a recompile or rebuild of ear to change the config file consider adding the config info into a POJO class, maybe a singleton. -
How to Read files in relative folder deployed in EAR (HELP!)[ Go to top ]
- Posted by: Randall Maier
- Posted on: February 18 2005 15:04 EST
- in response to VIJAY KHANNA
This will return the path to the file(s?) you're looking for. Note: "ejbs" is the first level directory in my ejb.jar file.
URL myURL = this.getClass().getClassLoader().getResource("ejbs/config/test.xml");
if (myURL != null){
return myURL.getPath();
}else{
return "the URL IS NULL";
}
Hope it helps.
Randall Maier
Versant Corporation. -
How to Read files in relative folder deployed in EAR (HELP!)[ Go to top ]
- Posted by: VIJAY KHANNA
- Posted on: February 18 2005 23:50 EST
- in response to Randall Maier
Thanks for your help Guys !
I am gonna try this out today and let you know if alls OK.
Peace
VJ -
Thanks ![ Go to top ]
- Posted by: VIJAY KHANNA
- Posted on: February 19 2005 01:09 EST
- in response to VIJAY KHANNA
Randall,
Thanks, your tip has helped !
Kris, maybe your suggestion is quite good.The XML's contain SQL Queries for external injection to the DAO. I wanted to avoid coupling of Java code with SQL queries. But your point is interesting as, the SQL's may require changes for optimization purpose and if the application is stopped, rebuilt and deployed as currently the XML's are part of EAR then, I clearly see this as not a very intellgient technique.Inspired from your idea, I will load the XML's external to the EAR and a mechanism introduced to detect changes in XML files by the application.
Peace
VJ -
Re: How to Read files in relative folder deployed in EAR (HELP!)[ Go to top ]
- Posted by: krishna k
- Posted on: June 26 2007 10:10 EDT
- in response to VIJAY KHANNA
hi VJ i am also having same requirement like as urs, i need to read xml files from a folder which is in my local system,based on the meta data in xml doc it has to take the documnts from other folder which is also reside in local system and have to upload in to VCM(vignette content management) so can u pl send me the java code which u have for more or less same type of functionality to my email krishnakiss at gmail dot com thanks in advance kk