Maven Jetty Plugin JNDI JDBC / DBCP configuration

November 7, 2008 by umanga

Yesterday,I literary spent almost 5 hours just to get JNDI DBCP working properly with maven jetty plugin.
Previously I used tomcat6 ,but I noticed that using maven/jetty I can save lot of deployment time during development. So same as lots of other guys struggled with this problem …it gave me a real pain for too long.. So I thought it would be nice to write a blog just in case this might helpful to anyone out there.

In short here are the important points:

1) JNDI configuration : Like META-INF/context.xml in Tomcat ; jetty uses WEB-INF/jetty-env.xml (There are other ways like configure in the jetty-server.xml , but i am not going to discuss them here since my idea is to simply move the project between tomcat and jetty)

Here is the jetty-env.xml:
<?xml version=”1.0″?>

<!DOCTYPE Configure PUBLIC “-//Mort Bay Consulting//DTD Configure//EN” “http://jetty.mortbay.org/configure.dtd”>

<Configure class=”org.mortbay.jetty.webapp.WebAppContext”>

<New id=”immunodb” class=”org.mortbay.jetty.plus.naming.Resource”>
<Arg>jdbc/ImmunoDB</Arg>

<Arg>

<New class=”org.apache.commons.dbcp.BasicDataSource”>

<Set name=”driverClassName”>com.mysql.jdbc.Driver</Set>

<Set name=”url”>jdbc:mysql://localhost:3306/ImmunoDB</Set>

<Set name=”username”>root</Set>

<Set name=”password”>immuno</Set>

</New>

</Arg>
</New>

</Configure>

Note that theres only two <Arg> arguments here ,and if you went through Jetty JNDI Documentation you might find you need to put 3 <Arg> tags.
This depends on the number of arguments in the constructor of “org.apache.commons.dbcp.BasicDataSource”,which changes with the jetty/jetty-maven-plugin version you use.

2) Jetty/Jetty-Maven version:
In POM add the jetty-maven-plugin , I prefer version 6.9.1,since in some versions there’s a bug which JNDI resources are not getting registered properly.

<build>

<plugins>

<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.9</version>
</plugin>
</plugins>
</build>

3) I case of JDBC/DBCP , put your jdbc-driver.jar and apache-dbcp.jars in the POM dependencies.
With tomcat you have to put these jars in $TOMCAT/libs folder (wont work if they are in WEB-INF/libs) , but in jetty you can put them in WEB-INF/libs.

Thats it..now u can access you JNDI source as follows”

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup(“java:comp/env”);
DataSource ds = (DataSource)
envCtx.lookup(“jdbc/ImmunoDB”);

Hope this helps.

Clean FTP library for Java – FTP4J

August 22, 2008 by umanga

Recently I was been assigned to write a FTP layer for a project at work.It needed to be supported all the funky FTP stuff like active,passive mode all kind of proxies like FTP,HTTP,SOCKS…etc.

At first I was little worried cause even in Apache Commons Net, it doesn’t support clear architecture for all those weird FTP stuff.Then I came up with this library FTP4J which saved my life.

FTP4J is well designed and easy to use library and best thing is its open-source and comes with LGPL license.

Buddhism – The ultimate truth of reality

August 13, 2008 by umanga

Recently I’ve been reading about science behind Buddhism and ultimate reality.I thought it would be nice to blog some of few facts that I understood so far.

It is clear that recent researches and studies of modern science have revealed many great parallelisms between Buddhism and science. Especially with Quantum physics, which look at the universe and at the reality in a complete different perspective , scientists amazed that these new results show a great similarities with Buddhas teachings which had been taught over 2500 years ago.

One of the amazing discoveries that scientists have made was the emptiness in matters.By experiments like ‘double slit experiment ‘,it is concluded that fundamental particles are empty of inherent existence and exist in an undefined state of potentialities. They become ‘real’ when a mind interacts with them and give them a meaning. Whenever there is not mind there is no meaning or no reality.This quantum emptiness is similar to the Sunyata in Buddhism,which is discussed in ‘Prajna Paramita Hridaya Sutra.’

Above mentioned undefined state of potentialities behave as a field of energy. According to Quantum physics, this field is considered as the fundamental level of the universe , which is called ‘Quantum Field’ or ‘Unified Field’. It is considered that fluctuations of this field give rise to so called ‘Realities’.So according to that the ‘Reality’ that we live in, is just another one of infinite number of realities.

Quantum physics have changed the way we look at reality. It is amazed to see that almost every finding in Quantum mechanics has a connection with teaching in Buddhism.

But scienstists have lots of things to learn.I think Quantum physics is still in its child stage.There are infinite amount of pure knowledge that scientists can get from teachings of Lord Buddha – The greatest “Quantum Physicist” ever.

Following are few of selected sources which I found useful to anyone who’s interested :

  • Where Science and Buddhism Meet 1/2:

http://www.youtube.com/watch?v=qj_i7YqDwJA

Great video, simply explain emptiness,interconnectivity and nature of reality.

  • Quantum Knowledge: Link
  • Every thought has a frequency : Link
  • Discovery of Unified Field : Link
  • Illusion of Reality : Link

Ubuntu is dying , Debian Lenny is the Future!

June 22, 2008 by umanga

I used Debian Etch for a long time even though several unstable versions of Lenny has been relased.So I thought to give it a shot for new Debian Lenny.So i downloaded Lenny Beta 2 DVD and the installation was smooth and easy.

Lenny comes with Gnome 2.22 and built in compiz and I  think people that complained that Debian is not that much attractive would change there attitude.I heard that Ubuntu making there releases half a year using Debian testing code base , so its obvious that, even this Beta is stable than Ubuntu8.I am not condemning Ubuntu ,but I have some bad experiences with Ubuntu.I used it about ~2 months at work and it really gave me a headache.I couldn’t run one instance of Eclipse and Tomcat with some heavy weight applications (Sun IDM…etc) .System behaved even worst than Window$.Yeah, I same applications ran smoothly in Window$ than in Ubuntu.

Anyway I always liked Debian , because its giving me the “pure” “GNUish” and “open source” feeling.There is no doubt that Debian is the future of OS.Ubuntu well…my feeling is its sinking…It has become to a something like “linux for dummies”.

Whatever the linux distro you are using ,take a look at this advertisement by IBM :

Beryl with flgrx + AIGLX in Debian Etch

November 1, 2007 by umanga

Beryl 

I have suffered over months to get Beryl working on my Toshiba Satellite with ATI Radeon x700.I found out that this was an issue every ATI mobility x700 users encountered.(Click here if you don’t know what beryl is)
Now finally, I managed to get it working with new ATI proprietary ‘flgrx’ driver.After installing the driver you have to configure the xorg.conf.

In the ServerLayout section add the option ‘AIGLX’

Section “ServerLayout”
     .
     .
    Option “AIGLX” “true”
EndSection

In the section ‘Module’ you should have ‘dri’,’glx’.In my xorg.conf its like

Section “Module”
   Load  “i2c”
   Load  “bitmap”
   Load  “ddc”
   Load  “dri”
   Load  “extmod”
   Load  “freetype”
   Load  “glx”
   Load  “int10″
   Load  “type1″
   Load  “vbe”
EndSection

In the ‘Device’ section you shoud have follwing options,notice that I am using the ‘flgrx’ driver

Section “Device”
   Identifier  “aticonfig-Device[0]“
   Driver      “fglrx”
   Option     “XAANoOffscreenPixmaps”
   Option      “AGPMODE” “4″
   Option      “AGPFastWrite” “true”
   Option      “DisableGLXRootClipping” “true”
   Option     “AddARGBXVisuals” “true”
   Option     “AllowGLXWithComposite” “true”
   Option     “EnablePageFlip” “true”
EndSection

Also you should have following sections:

Section “DRI”
      Mode         0666
EndSection

and

Section “Extensions”
    Option     “Composite” “Enable”
EndSection

That’s it.Now you can run ‘beryl-manager’ and enjoy the eye candy.
(beryl debian packages  can be found at http://debian.beryl-project.org )

For more info visit beryl home page http://www.beryl-project.org

To download ATI proprietary linux driver (flgrx) visit www.ATI.com

Disabling touchpad in linux

October 31, 2007 by umanga

synaptics touchpad 

Most of the time the “Fn” + “key”s are not functioning in Linux.(Well.. its not working for me, even though I have installed Omnibook module for Toshiba laptops ).So the touch pad is always turned on and it’s a real headache if you are doing lot of coding stuff.
I found a method to disable the touchpad using ‘xserver-xorg-input-synaptics’ kernel module.

First you have to install ‘xserver-xorg-input-synaptics’ .In Debian based system its
apt-get install xserver-xorg-input-synaptics

Then you have to edit your xorg.conf file.
Add a new “InputDevice” section, in addition to the section for your mouse.

Section “InputDevice”
   Driver “synaptics”
   Identifier “Mouse[1]”
   Option “Device” “/dev/psaux”
   Option “Protocol” “autodev”
   Option “SHMConfig” “on”
EndSection

And in the “ServerLayout” section add an entry for the new synaptic touchpad like, and for your primary mouse (in my case – Configured mouse) add the option “CorePointer”.

 Section “ServerLayout”
     InputDevice “Mouse[1]” “AlwaysCore”
     InputDevice “Configured mouse” “CorePointer”
    .
    .
EndSection

Then restart the X server and type the command ‘synclient TouchPadOff=1’ , WOILA..your touchpad is now disabled. If you play with ‘synclient’ command , you can notice that there’s many settings for the touchpad. I am writing a small python GTK proggie, visit here soon to download it.

Linux Kernel 2.6.23

October 15, 2007 by umanga

As you may probably know, the linux kernel 2.6.23 has been released.This kernel features a new process scheduler- CFS (Completely Fair Scheduler) and many more features. Checkout http://kernelnewbies.org/Linux_2_6_23. So I thought to give it a shot.I downloaded it and configured the kernel for my Toshiba Satellite M40 with a Centrino processor. I feel theres a performance boost with the new kernel.

FOSS-ed On Wheels Ratnapura @ Ruwanpura National Collage of Education (RNCOE)

October 10, 2007 by umanga

img_2995.JPG    

Last Saturday, I had this great opportunity to give my support to  ‘Linux Traning  workshop at Ratnapura’ .Event was held at Ruwanpura National College of Education , targeting IT teachers in Ratnapura area.
We (Sagara and Me) started the journey from Colombo at 4.00am and got on to the Ambilipitiya bus at 5.00am.We reached the place at about 9.00am.

Place was a nice, and when we got there,Sucheta, Kunchana and Bikku Metta Vihari had already finished installing Ubuntu and Edubuntu on machines.

After the starting ceremony, I had to give support in laboratory. I basically did hand on to Linux desktop, file system..Etc while other student-set were given a presentations on OpenOffice, Desktop environments..etc.

After the lunch, I did a small introductory speech on ‘OpenOffice Spreadsheet’ and again back to laboratory to do some particles on spreadsheets.

At about 5pm we were able to finish the schedule and went to our crashing place. After having a wash we watched some movies (including American Pie 5: naked mile;, Die Hard 4) while having some beers and at about 12.00pm I crashed to bed.

The sad part is, even though the event was a two day workshop I only had the chance to attend to the first day only. So early Sunday morning me and Sagara packed our gear and headed back to Colombo.

I really enjoyed hanging out with FOSS guys and giving my knowledge FREELY!. I am trying my best to give my support for future events like this.

img_3000.JPG  img_3008.JPG

img_3014.JPG  img_3030.JPG

img_2983.JPG 

 

 

Last King of Scotland

September 8, 2007 by umanga

last_king.jpg

Few weeks back, I watched the movie Last king of Scotland. It has won several awards including “Best Actor (Idi Amin-Forest Whitkaer)” in Academy Awards 2007, Golden Globe Awards…etc. At the begging I thought its more like the other films based on racism like “Hotel Rwanda” and “Shooting Dogs” , but its little more different that than.
When I was watching the film, I realized how much its relate to leaders of our country, (well they don’t eat human flesh like Idi Amin, but they suck their blood).
In the movie, there’s a scene when “Idi Amin” address the people. There he’s giving hope to the people about a developed, prosperous and a unified Uganda. It came to my mind of what our leaders tell us throughout our history. About their fairytales, how they going to develop the country, make our economy strong…
In the movie “Uganda” people reflected the exact way how our people react. How people get fascinated and how they day dreaming about the sweet stories that their Amin told them.
So it’s up to us, to stop the “Idi Amins” who destroying our country, moving our motherland to hell…lets pray that our people will realize this someday…

Transformers

August 15, 2007 by umanga

 

Ok the truth is I couldn’t wait to watch it, since I watched the trailer in Yahoo Movies. I remember got a ‘Japanese Transformer’ comic book when I was a kid and I’ve played with several Transformer toys (of course when I was a kid… :) ).
So.. Right after a week the, movie came to MC Cinema; I gathered all my friends on last Tuesday (I really wanted to share the full enjoyment with my buddies) and went there at 6.30pm. There was a considerable queue at that time, so it was good idea to go earlier.
Anyhow I couldn’t find a seat in the center of the back rows- which is my favorite spot to enjoy movies.
Movie started at 7.30pm starting with a modified version of DreamWorks logo with a transformers robotic-voice. At beginning I was little bit worried with the sound, because compared to Savoy cinema, it had less quality DTS sound.
I heard that the Transformers has the record for longest rendering time for a frame, i.e. ~38hours.I was not amazed about that because the details of the robots were amazing. Fighting scene were Adrenalin pumping, and most of the crashes, stunts, blasts were done in real environment without using computer graphics because the director Michael Bay wanted to give the real thrill for the audience.
The story was ok; had the fun, humor, little bit of romance and LOTS of action. So it’s a well balanced movie to watch, enjoy and relax.
After the movie, all of my buddies accepted, that it was a great movie. I heard that there’s going to be two more sequels and now I’m waiting for hear any news about them…