This will all getting the base path of you application to know how/where to read the file
Eclipse
Java Application
* File function
File fXmlFile = new File("test.xml");The will look on the PROJECT_DIR path.
/YOUR/PROJECT_DIR/test.xml* FileInputStream
FileInputStream is = new FileInputStream("test.cfg.xml");
The will look on the ECLIPSE path.
/YOUR/ECLIPSE_DIR/test.cfg.xml
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();This will return: PROJECT_DIRt/build/classes/
classLoader.getResource(".").getPath()
Web Application(Running in Tomcat)
* Loader context
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();This will return the path TOMCAT_DIR/lib/
classLoader.getResource(".").getPath()
* File function
File fXmlFile = new File("test.xml");The will look on the ECLIPSE_DIR path.
/YOUR/ECLIPSE_DIR/test.xml
Deployed
* Java Application
* Web Application(Running in Tomcat)
* Loader contextClassLoader classLoader = Thread.currentThread().getContextClassLoader();This will return the path TOMCAT_DIR/lib/
classLoader.getResource(".").getPath()
* File functionFile fXmlFile = new File("test.xml");The will look on the TOMCAT_DIR path.
/TOMCAT_DIR/test.xml
No comments:
Post a Comment