It depends... if your application is a web application, it can be packaged as a war, or an expanded war, be deployed in a web container, or embed its own web container. That's a lot of different cases, so there is no single answer to your question. The best is to keep things either in your classpath and access them as resources (using Class#getResource(String) or Class#getResourceAsStream(String)) or in your webapp (in WEB-INF for instance) and access them using ServletContext#getResource(String) or ServletContext#getResourceAsStream(String). Then you don't need to actually know where your app is deployed and how. If you are sure your webapp will be deployed expanded, you can still try to figure out your project path out the URL returned by ServletContext#getResource(String). But it will make your webapp very dependent on how it's deployed, which is usually not a very good idea.
HTH, Xavier On 9/1/07, Edi <[EMAIL PROTECTED]> wrote: > > > Thanks for your reply, > > How to find the base path of the project > > For e.g my project name is TMS. this projected stored in c:/program > files/TMS. > How to find the above path using java program. > > Thanking You. > > > Xavier Hanin wrote: > > > > Oops, sorry, WEB-INF is usually not accessible in your application > > classpath, but through the ServletContext. > > > > So you can access it with: > > > ((WebApplication)WebApplication.get()).getServletContext().getResourceAsStream("/WEB-INF/conf/database.properties") > > > > Xavier > > > > On 9/1/07, Xavier Hanin <[EMAIL PROTECTED]> wrote: > >> > >> This is not really related to wicket, since your properties file is > >> available in your classpath, you should be able to get it as a > resource. > >> Something like: > >> Properties props=new Properties () ; > >> props.load ( > >> getClass().getResourceAsStream("/WEB-INF/conf/database.properties") ) ; > >> > >> If you're in a static method of class initializer, you'll need to refer > >> to > >> the class using MyClass.class before the getResourceAsStream(). Note > that > >> you can actually use any Class object, since the path to the resource > is > >> absolute (starting with a slash). > >> > >> HTH, > >> > >> Xavier > >> On 9/1/07, Edi <[EMAIL PROTECTED]> wrote: > >> > > >> > > >> > Hello, > >> > > >> > I have one sample project named as TMS, In my "WEB-INF/conf" foler > >> > contains > >> > database.properties file. It contains > >> > > >> > e.g > >> > hostname = some host name > >> > url= some url > >> > > >> > This project contains only one database.properties file. > >> > In java file, I want to get hostname and url from that property file. > >> > > >> > e.g. > >> > > >> > Properties props=new Properties () ; > >> > props.load ( new FileInputStream ( new File > >> > ("E:\\Workspace\\TMS\\WebRoot\\WEB-INF\\conf\\database.properties"))) > ; > >> > > >> > String host= "hostname"; > >> > String val = props.getProperty ("Host Name Is :"+ host ) ; > >> > > >> > Using the above code, I have got both hostname and url. > >> > > >> > But my problem is, How to get the current project > >> database.propertiesfile > >> > path. > >> > > >> > Because in the above path name is hard coded. > >> > > >> > So How we get current project database.properties file path? > >> > > >> > Thanking you. > >> > > >> > -------------------- > >> > > >> > Thank You > >> > Edward > >> > -- > >> > View this message in context: > >> > http://www.nabble.com/How-to-get-path-name--tf4363832.html#a12438194 > >> > Sent from the Wicket - User mailing list archive at Nabble.com. > >> > > >> > > >> > --------------------------------------------------------------------- > >> > To unsubscribe, e-mail: [EMAIL PROTECTED] > >> > For additional commands, e-mail: [EMAIL PROTECTED] > >> > > >> > > >> > >> > >> -- > >> Xavier Hanin - Independent Java Consultant > >> http://xhab.blogspot.com/ > >> http://incubator.apache.org/ivy/ > >> http://www.xoocode.org/ > > > > > > > > > > -- > > Xavier Hanin - Independent Java Consultant > > http://xhab.blogspot.com/ > > http://incubator.apache.org/ivy/ > > http://www.xoocode.org/ > > > > > > -- > View this message in context: > http://www.nabble.com/How-to-get-path-name--tf4363832.html#a12439360 > Sent from the Wicket - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- Xavier Hanin - Independent Java Consultant http://xhab.blogspot.com/ http://incubator.apache.org/ivy/ http://www.xoocode.org/