Sitemap

Amicuk Programming Answers

Loading property files from a class and not a servlet...

-0001-11-30   Views:0

Advertisement

Hi, I was wondering if anyone has a good solution for loading property files from a class instead of a servlet. I would like to load the property file similarly to how it is done from HttpServlet. Here is the large picture. I have a tag library that

Hi, I was wondering if anyone has a good solution for loading property files from a class instead of a servlet. I would like to load the property file similarly to how it is done from HttpServlet.
Here is the large picture. I have a tag library that calls a class which needs to access a database. The class needs to know what DB to access so it needs to look at some property file. The problem is that I don't want to hardcode the properties or the path of where the property file exists. I hope this all makes sense.
Thanks.
-PV

The replay answer
Advertisement
I use the getResource method in the java.lang.Class class. Read about this method in the api.
Anyways this is roughly how it's : you must put your properties file in the classpath. Then in your class :
Properties prop = new Properties();
URL url = this.getClass().getResource("/config/db.properties");
prop.load(url.openStream());In this case, you must put the "config" (where you've written your db.properties file) directory's parent in the classpath.

Go to See the other 2 answers

Loading property files from a class and not a servlet...

Category:DefaultRelease time:-0001-11-30Views:130

Hi, I was wondering if anyone has a good solution for loading property files from a class instead of a servlet. I would like to load the property file similarly to how it is done from HttpServlet. Here is the large picture. I have a tag library that[More]

How do I load property files and images stored in the jar file?

Category:DefaultRelease time:-0001-11-30Views:130

Hi So, if I have a structure like this: /com.myfirm.myproject.SomeClass /images/ /properties/ And I pack this structure into a jar file, how do I then access the images under "/images/" and the property files under "/properties/"? A li[More]

Load property file in init(PortletConfig) method of JSR 286 portlet

Category:DefaultRelease time:-0001-11-30Views:130

I store my configuration in .properties file. Now I want to load this file only once, so I decided to load it in init(poerletConfig) method. But now I'm confused to where to put this file, so it can be loaded in this method. I'm using following code:[More]

Best practice for property file

Category:DefaultRelease time:-0001-11-30Views:130

I am trying one small code which uses values from property file. public void doPost(HttpServletRequest request, HttpServletResponse response)   throws ServletException, java.io.IOException       InputStream inputStream = servletContext.getResourceAsS[More]

Load html errors undefined property File

Category:DefaultRelease time:-0001-11-30Views:130

in the following code take 4 errors on 2 bold lines mdapp, Layer 'inputpage', Frame 1, Line 25 1046: Type was not found or was not a compile-time constant: File. mdapp, Layer 'inputpage', Frame 1, Line 26 1046: Type was not found or was not a compile[More]

How can i get the all values from the Property file to Hashtable?

Category:DefaultRelease time:2015-10-11Views:130

how can i get the all values from the Property file to Hashtable? ok,consider my property file name is pro.PROPERTIES and it contain 8326=sun developer 4306=sun java developer 3943=java developer how can i get the all keys & values from the pro.PROPE[More]

Loading jar files at execution time via URLClassLoader

Category:DefaultRelease time:2015-10-11Views:130

Hello�All, I'm�making�a�Java�SQL�Client.�I�have�practicaly�all�basic�work�done,�now�I'm�trying�to�improve�it. One�thing�I�want�it�to�do�is�to�allow�the�user�to�specify�new�drivers�and�to�use�them�to�make�new�connections.�To�do�this�I�have�this�class:[More]

Relative path for servlet property file.

Category:DefaultRelease time:2015-10-11Views:130

I have the following java file. When I use the absolute path for the configFile, it works. I would like to know how I could use it as relative path as in installation, the name of the directory could change. How do I fix the problem? Thank you. -----[More]

Maven Plugin not accepting values from a property file.

Category:DefaultRelease time:2015-10-11Views:130

Hi, I want to create javadocs using maven. It works fine when i provide all the absolute paths in the pom. But when i try to provide paths by reading a property file then the maven-javadoc-plugin does not get the paths from this property file. The pr[More]

Applet can't Load a file from outside it's JAR??

Category:DefaultRelease time:2015-10-11Views:130

My loading code: (note: I have also tried ...getResourceAsStream("menu.properties");... ) codeBase = getCodeBase(); InputStream is = getClass().getResourceAsStream( new URL( codeBase, "menu.properties" ).toString() ); if( is == null )[More]

How can I display the front panel of the dinamically loaded VI on the cliente computer, the VI dinamically loaded contains files, I want to see the files that the server machine has, in the client machine

Category:DefaultRelease time:2015-10-11Views:130

I can successfully view and control a VI remotly. However, the remote VI dinamically loads another VI, this VI loaded dinamically is a VI that allows open others VIs, I want to see the files that contains the server machine, in the client machine, bu[More]

Hot
Hi All, Good Day, We have Logical System field in BD10 or BD14 etc.. TCodes and I would like to make this field as a Mandatory field. The reason for this is, while sending the Materials using BD10, and If I haven't enter any value for this field, IDO [More]
Hi evey body: Can you please help me with the JButton problem ...?? I give it the focus using requestFocus() but when I press Enter from the keyboard it doesn't click??? JButton Btn = new JButton("Ok"); Btn.requestFocus(); Btn.addActionListener( [More]
I am wondering if anyone could give me a brief overview of how the Java sun forums work -- esp. when someone creates a new thread. How exactly does the JSP know to link to that thread? Is it generating a unique ID from the database or using it's own [More]
Hi, I connected my iPhone 5s (iOS 8 latest version) to my Mac (OS Yosemite latest version). When iPhoto (ver. 9.6) automatically opens it sees a double copy for every pictures stored on the iPhone. Theres a way to solve this problem? Thanx.The same b [More]
I'm using the Yoga 13 for about 2 weeks now and I'm very happy with the device! Does the Yoga have digitizer stylus support? And can you recommend a stylus for the Yoga? Thanks BmelkI am starting to like my computer but I would like a bit more precis [More]
I  just purchased the Camera Connection Kit and it will not download video. Warning comes up stating " the attached device uses too much power"I have tried the SD and USB and neither works for video. Camera is HD 7.8 mega pixel cam corder (Samsu [More]
Hiee friends ,          I am new to workflow and learning it from sdn blogs and elearnings .          My workflows were running fine but only recently there is a error every time i execute my workflow .          Evertime i execute my workflow , a def [More]
Hi we are using SharePoint 2010 with FAST search... I'd like to be able to search for this exact string that contains parentheses...  "(ABC)" I thought it would be: ManagedProperyName:"(ABC)" this returns results with just ABC ... it i [More]
Hello everyone. Sum of a holder of a PPC G4 and I am very pleased by the fact, and my question is as follows. The parameters are: - 1gb SD RAM - CPU 933Mhz - 60 HDD - GForce 4MX, 64MB He is currently with Tiger 10.4 but I would like to put Win Xp to [More]
Hello everybody, since I use itunes 11.0.2 it is not possible to sync my calender(s) from my macbook with my iphone. I tried to use other calenders, try to sync with icloud, tried everything which I think is possible. But always with the same result: [More]