2013年7月31日 星期三

Weblogic: Properties and xml files under WEB-INF/classes disappear after deployment

on WebLogic 10, all the Properties files and xml files will be on the _wls_cls_gen.jar file after deployment.
_wls_cls_gen.jar file will save under _WL_user/[application]... /lib folders.

zip:C:/bea103/user_projects/domains/Test_Domain/servers/AdminServer/tmp/_WL_user/testWebApp/8j5e1y/war/WEB-INF/lib/_wl_cls_gen.jar!/test.properties 

Now if we write the following code inside out application like Servlet then it won’t work and will fail while reading the Properties file: 

Note: Many frameworks uses the Following techinques and Sometimes WebLogic Code causes this issue..(http://forums.oracle.com/forums/thread.jspa?messageID=4217650#4217650)…which may cause our applications to fail while reading jar Archieved resources. because they uses the following techinque to read the resources available inside a JAR file: 

Change code:
  1. InputStream stream = null;  
  2.   
  3. try {  
  4.   
  5. Properties p = new Properties();  
  6.   
  7. String path=Thread.currentThread().getContextClassLoader().getResource(“Info.properties”).getPath();  
  8.   
  9. System.out.println(“—————-PATH: “+path);  
  10.   
  11. p.load(new java.io.FileInputStream(path));  
  12.   
  13. Host = p.getProperty(“Host”);  
  14.   
  15. Pot = p.getProperty(“Port”);  
  16.   
  17. User = p.getProperty(“User”);  
  18.   
  19. Passwd = p.getProperty(“Passwd”);  
  20.   
  21. System.out.println(“Property Key-Values:” +”\n”+ Host +”\n”+ Pot + “\n”+User+ “\n”+Passwd);  
  22.   
  23. catch (Exception e) {  
  24.   
  25. e.printStackTrace();  
  26.   
  27. }  


To:

  1. InputStream stream = null;  
  2.   
  3. System.out.println(“————————————”);  
  4.   
  5. try {  
  6.   
  7. Properties p = new Properties();  
  8.   
  9. stream=this.getClass().getClassLoader().getResourceAsStream(“Info.properties”);  
  10.   
  11. p.load(stream);  
  12.   
  13. Host = p.getProperty(“Host”);  
  14.   
  15. Pot = p.getProperty(“Port”);  
  16.   
  17. User = p.getProperty(“User”);  
  18.   
  19. Passwd = p.getProperty(“Passwd”);  
  20.   
  21. System.out.println(“Property Key-Values:” +”\n”+ Host +”\n”+ Pot + “\n”+User+ “\n”+Passwd);  
  22.   
  23. catch (Exception e) {  
  24.   
  25. e.printStackTrace();  
  26.   
  27. }  


沒有留言:

張貼留言