2013年7月31日 星期三

WebLogic: Setup log4j for your Java Application

This is from: "http://phillips4jc.blogspot.com/2012/01/configuring-web-logic-1035-and-log4j.html"

I recently spent several days trying to track this down why Apache log4j for my Java application was working when deployed to Oracle WebLogic Server 10.3.5. I am posting my findings here in the hopes of saving others some time. I found several blogs that talked about this, but the end result was that log4j was still not working correctly. There was always one step missing. A co-worker and I finally figured it out for both Linux and Windows.

1. Copy wllog4j.jar from your WebLogic server/lib directory and place it in your domain_root/lib folder.
2. Copy your version of log4j.jar to your domain_root/lib folder.
3. Copy your log4j.xml to your domain_root folder. 
4. Log in to the your WebLogic admin server console. Click on Servers -> Admin Server -> Logging. Click on advanced mode, and change the logging implementation from JDK to Log4J. Save your changes.

Most of the blogs had these items, but the one critical piece that was missing:
5. (Linux)Edit the setDomainEnv.sh file in the domain_root/bin directory. and find the following code:

if [ "${LOG4J_CONFIG_FILE}" != "" ] ; then
       JAVA_PROPERTIES="${JAVA_PROPERTIES} -Dlog4j.configuration=file:${LOG4J_CONFIG_FILE}"
       export JAVA_PROPERTIES
fi

Insert the following above those lines of code(replacing the path with the one for your system's domain_root directory:

LOG4J_CONFIG_FILE=”/u01/app/oracle/middleware/user_projects/domains/base_domain/log4j.xml”
Export LOG4J_CONFIG_FILE

5. (Windows)
Edit the setDomainEnv.cmd file in the domain_root/bin directory. and find the following code:

if NOT "%LOG4J_CONFIG_FILE%"=="" (                                                          
            set JAVA_PROPERTIES=%JAVA_PROPERTIES% -Dlog4j.configuration=file:%LOG4J_CONFIG_FILE%
)

Insert the following above those lines of code(replacing the path with the one for your system's domain_root directory:

set LOG4J_CONFIG_FILE=”C:\Oracle\Middleware\user_projects\domains\base_domain\log4j.xml”


6. Activate the changes and restart the admin server.

Here is a sample log4j.xml file. Obviously, you will need to update it for a valid location for your file appender, and replace yourcompany and yourproject with valid values.





   
   
   
    
        
        
            
            
        
    

    
        
        
        
            
        
    

    
    

    
      
    

    
        
    

    
        
    

    
    
    
        
        
    

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. }  


2013年7月25日 星期四

JAVA on running Unix command: Not enough space

That's not what you think of "disk space". It means not enough swap, because your Java suddenly wants lots of GB of memory. When Java launches fork, it starts a new VM as a fork from current process. Thus for a short period between fork and exec, there is two instances of your stuff. That's temporary though. Exactly at this moment your system cries for a lack of swap.