31 Ekim 2012 Çarşamba

How do I Use My Own log4j properties or xml File in JBoss AS 7


Keywords: Classloader isolation, JBoss7, JBoss 7, JBoss AS7, JBoss AS 7, log4j

I've been away from Java world for 4 years and looks like the technology is advanced and I forgot some of my knowledge. So, please forgive me and correct me if you encounter something wrong on this article.

This article is like an updated version of  Jaikiran's article. Please read that article if you need to configure previous versions of JBoss AS. The strategy described on that article may still work on JBoss AS7 but I could not made it work.
 
JBoss uses log4j for its internal logging capabilities. So when JBoss loads up it loads log4j jar along with other jars. This is described as Automatic Dependencies on JBoss documentation. Packages listed in 
Implicit module dependencies for deployments page are not isolated on EAR or WAR classloader. Thus root Logger of log4j is shared with your application's instance and it is configured using the configuration in standalone.xml file of JBoss. 

We need to remove org.apache.log4j package from Automatic Dependencies list of JBoss on a Dynamic Web Project (WAR). Here is how to do it: 


1. Create a jboss-deployment-structure.xml file in WEB-INF directory.

2. Edit its content like displayed below:
xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>     
       <deployment>
             <exclusions>
                    <module name="org.apache.log4j" />
             </exclusions>
       </deployment>
</jboss-deployment-structure>

3. Put log4j-x.y.zz.jar into your WEB-INF/lib directory.
4. Add log4j.xml or log4j.properties into root of your src directory.
5. Optionally copy log4j.dtd from log4j-x.y.zz.jar for syntax checking.

Troubleshooting:
If you encounter any problems open up your standalone.xml and change logging levels to TRACE on urn:jboss:domain:logging:1.1 section. Then start your JBoss server. There will be a lot of log messages but you might find some crucial information explaining what went wrong. (i.e. searching "jboss-deployment-structure.xml" keyword in the log helped me.)

Attach source code of log4j to your project, find org.apache.log4j.LogManager.class, open it up and put a breakpoint to the class. (Just like on the image below) Upon starting the server this breakpoint must be hit twice. One for JBoss startup (possibly it will hit the breakpoint and you won't see the source code, so don't worry about it) and one for your application startup

Happy coding ;)






2 Şubat 2012 Perşembe

Installing Edimax EW-7711UMn Driver on Ubuntu 10.04

Edimax EW-7711UMn drivers are not automatically recognized by Ubuntu. However, driver can be built and installed on your operating system in by following steps below.

1.Do not insert your EW-7711UMn until I say so. If you've inserted, remove it and reboot your os before continuing.
2.Download driver file from www.ralinktech.com
1.EW-7711UMn uses RT3070 chipset
2.Go to support page, find corresponding driver
3.Ralink released a generic driver which support both RT5370 and RT3070 and etc. so compiled driver file name might be different than RT3070. This is OK.

3.Extract driver to a folder (we'll assume the root folder is Ralink)
1. gedit Ralink/os/linux/config.mk
1. Change HAS_WPA_SUPPLICANT=n to
HAS_WPA_SUPPLICANT=y
2. Change HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n to
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y (This will enable Ubuntu's Built-in Network Manager access to the device)
2. sudo make
3. If any problem occurs on compilation see README_STA_usb file located inside Ralink folder.
4. sudo make install
This will install driver module files onto the linux kernel
1. Check Ralink/os/linux/*.ko
2. It should contain a file named rtXXXXsta.ko (in my case it is rt5370sta.ko)
3. This file should have been installed as kernel module
4. Try on command line if it succeeded. (Do not execute the command yet!) Type
insmod rt5370 [and then press TAB]
terminal should automatically complete it.
5. Clear the command line
5. Insert your Edimax EW-7711UMn into your USB at this point
6. You can check if the driver is loaded by issuing
lsmod | grep rt
result should contain something like rt53xxx , rt30xx
7. If lsmod result contains rt28xxx type modules instead of rt53xxx, it is most likely that wrong driver is automatically loaded by Linux. Test by first unloading the wrong modules. If it succeeds we'll blacklist invalid drivers. My computer loaded rt2x00usb , rt2x00lib , rt2800usb , rt2870sta and driver module name is rt5370sta.ko So example below will unload / load these drivers.
1. Remove Edimax EW-7711UMn
2. sudo rmmod rt2800usb
3. sudo rmmod rt2870sta
4. sudo rmmod rt2x00usb
5. sudo rmmod rt2x00lib
6. sudo insmod rt5370sta.ko
7. lsmod | grep rt
Result should contain rt5370sta but not rt2xxx
8. Insert Edimax EW-7711UMn
9. You should be able to connect your preferred wireless network using Network Manager at this moment.
10. If your connection is successful, then we should blacklist invalid drivers permanently. (If you reboot now, invalid drivers will be loaded again)
8.Blacklist invalid drivers
1. gksudo gedit /etc/modprobe.d/blacklist.conf
2. Add the lines below to the blacklist.conf
blacklist rt2x00usb
blacklist rt2x00lib
blacklist rt2800usb
blacklist rt2870sta
3.Save the file
4. Reboot

Enjoy...