Total Pageviews

Friday, February 10, 2012

Updating GlassFish 3.1 under RHEL 6 on a 64 Bit machine

Don't be surprised when you have problems updating GlassFish 3.1 on a RedHat Enterprise Linux 6 64 Bit machine. This will not work out of the box (officially Oracle only supports GlassFish on RedHat 4 and 5 not on version 6). But there is a way to get it to work.
You will get this error when executing the pkg command:

 [glassfish@MYMACHINE glassfish3]$ pkg list -u  
 Traceback (most recent call last):  
  File "/opt/glassfish/glassfish3/pkg/bin/client.py", line 61, in ?  
   import pkg.actions as actions  
  File "/opt/glassfish/glassfish3/pkg/vendor-packages/pkg/actions/__init__.py", line 59, in ?  
   globals(), locals(), [modname])  
  File "/opt/glassfish/glassfish3/pkg/vendor-packages/pkg/actions/link.py", line 36, in ?  
   import generic  
  File "/opt/glassfish/glassfish3/pkg/vendor-packages/pkg/actions/generic.py", line 45, in ?  
   import pkg.variant as variant  
  File "/opt/glassfish/glassfish3/pkg/vendor-packages/pkg/variant.py", line 28, in ?  
   from pkg.misc import EmptyI  
  File "/opt/glassfish/glassfish3/pkg/vendor-packages/pkg/misc.py", line 49, in ?  
   import zlib  
 ImportError: libz.so.1: cannot open shared object file: No such file or directory  
 ---------------------------------------------------------------  
 There was an error running  
   
 /opt/glassfish/glassfish3/pkg/bin/../python2.4-minimal/bin/python  
   
 You are running on a 64 bit Linux distribution and the 32 bit Linux  
 compatibility libraries do not appear to be installed. In order to use  
 the Update Center tools you must install the 32 bit compatibility libraries.  
   
 On Ubuntu (and possibly other Debian based systems) please install the  
 ia32-libs package. On RedHat 4 (and other RPM based systems), you may  
 need to add multiple 'compat' runtime library packages. Please see the  
 Update Center Release Notes for more information.  
   
   

The solution is to install the following packages using yum

yum install compat-db.i686 zlib.i686 libidn.i686 krb5-libs.i686

The trick is to find out about the correct names of the packages. It's easy on Debian based systems but quiet difficult on RPM based systems.
If you are using CentOS take a closer look at this blog post.

Monday, February 06, 2012

Deep cloning of java objects

I was in need of deep cloning a map with all its keys and values.
All the map implementations in standard Java only do shallow cloning of the map. They don't clone the keys and values. But that was exactly what I want to realize.
I found out about the cloning library which does the job very easy and extremely fast. This library can clone nearly any java object.
A cloning expression is just a two-liner.
Very useful!
On this stackoverflow question you can find more deep cloning libraries.

Thursday, February 02, 2012

Don't use commons lang < 2.4 with HtmlUnit

In case you have a project which has a dependency to Apache commons-lang and you plan to use the latest HtmlUnit (as of writing this post this is HtmlUnit 2.9) you should take care of the version of commons-lang.

HtmlUnit is using a method (startsWithIgnoreCase) from commons-lang that was introduced in commons-lang 2.4.
So any commons-lang version below 2.4 will produce runtime exceptions when using HtmlUnit. The stacktrace may be similar to this one:

 java.lang.NoClassDefFoundError: Could not initialize class  
 com.gargoylesoftware.htmlunit.WebClient  
     at net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl.createWebClient(HtmlUnitTestingEngineImpl.java:804)  
     at net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl.initWebClient(HtmlUnitTestingEngineImpl.java:813)  
   
 also :  
   
 java.lang.NoSuchMethodError:  
 org.apache.commons.lang.StringUtils.startsWithIgnoreCase(Ljava/lang/String;Ljava/lang/String;)Z  
     at com.gargoylesoftware.htmlunit.util.URLCreator$URLCreatorStandard.toUrlUnsafeClassic(URLCreator.java:66)  
     at com.gargoylesoftware.htmlunit.util.UrlUtils.toUrlUnsafe(UrlUtils.java:193)  
     at com.gargoylesoftware.htmlunit.util.UrlUtils.toUrlSafe(UrlUtils.java:171)  
     at com.gargoylesoftware.htmlunit.WebClient.<clinit>(WebClient.java:162)  
     at net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl.createWebClient(HtmlUnitTestingEngineImpl.java:804)  
     at net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl.initWebClient(HtmlUnitTestingEngineImpl.java:813)  
   
   
   

In case you use Maven as your build tool you can check the dependencies using the command:

mvn dependency:tree

To avoid this error you can declare version 2.6 of commons-lang in your project.

Friday, January 20, 2012

Iterating over result list from a JPA query

Sometimes when using EJB 3.x, it is necessary to use JPA QL or SQL native queries to fetch objects from the database. It might be used to achieve better performance or to just fetch a particular set of attributes of the object but not the complete object with all its dependencies.

There's one thing you have to keep in mind when doing this: The result list containing the object will be an array of objects!

"The SELECT clause queries more than one column or entity, the results are aggregated in an object array (Object[]) in the java.util.List returned by getResultList( )"

Working example:
 Query query = manager.createQuery("SELECT v1.bitbit, v1.numnum, v1.someTime, t1.username, t1.anotherNum FROM MasatosanTest t1 JOIN MasatoView v1 ON v1.username = t1.username;");  
   
   List results = query.getResultList( ); // Fetches list containing arrays of object  
   
   Iterator it = results.iterator( );  
   
   while (it.hasNext( )) {  
   
     Object[] result = (Object[])it.next(); // Iterating through array object   
   
     Boolean first = (Boolean) result[0]; // Fetching the field from array  
   
     /* Likewise for all the fields, casting accordingly to the sequence in SELECT query*/  
   
   }  
   
   

There's is even the possibility to avoid casting completely by using a constructor expression with the appropriate arguments in the SELECT section:
 SELECT new org.somepackage.XEntity(x.a, x.b) FROM XEntity x  

Remember to declare the appropriate constructor.
The code fragments and the solution in this blog post was taken from this question on stackoverflow.


Monday, January 16, 2012

How to change the DB schema to dbo on SQLServer 2008

Every now and then you are in need to backup and restore databases from one SQL Server to another. Furthermore, sometimes the version of the source SQL Server differs from the version of the target SQL Server.
With SQL Server 2008 Microsoft separated users from schemas.
Imported tables of an imported database may only become accessible with a prefix like "jonathan.MY_TABLE_NAME".
You can change the schema name of those tables using the ALTER SCHEMA command.
It is described in more detail here.
In my case it worked.

Friday, January 06, 2012

How to solve " Target Filesystem doesn't have /sbin/init" on Ubuntu 10.04


I restarted my Ubuntu 10.04 box today and it wouldn't start. It gave me this error:

 mount: mounting /dev/disk/by-uuid/***************************** on /root  
 failed: Invalid argument  
 mount: mounting /sys on /root/sys failed: No such file or directory  
 mount: mounting /dev on /root/dev failed: No such file or directory  
 mount: mounting /sys on /root/sys failed: No such file or directory  
 mount: mounting /proc on /root/proc failed: No such file or directory  
 Target file system doesn't have /sbin/init  
 No init found. Try passing init= bootarg  

So after googling around I found out that this seems to be a common problem ;-)
I have a JMicron RAID controller in my box using a RAID mirror but that doesn't help very much :-( It's a logical error and therefore replicated on the other disk as well.

I found this forum entry which helped me a lot and applied the fix using the following steps:
  1. Install GParted on an USB Stick using Tuxboot (my Linux box does not have a DVD drive)
  2. Boot GParted and wait until the graphical partition editor comes up
  3. Identify the boot partition (mounted on /). My boot partition is named "/dev/mapper/jmicron_GRAID1"
  4. Open a terminal and type in the following command
    sudo e2fsck -f -y -v /dev/mapper/jmicron_GRAID1
  5. When e2fsck finishes it usually must have been corrected some errors. So it's best to take a look into the summary.
  6. Reboot your system
After I applied these steps my system booted up without errors again.
Now I need to identify the source of the problem ...

Thursday, December 08, 2011

Using the Blogger app to post blog entries under android



Well this entry was published using the android app "Blogger" from Google via my milestone.

Seems to work very nicely.

...  2 days later...

Blogger has some drawbacks. On My gingerbread milestone it crashes everytime I try to insert an image.

So now I have switched to "blogaway".

Wednesday, December 07, 2011

Wie man die Größe des Systemfonts in Ubuntu 11.10 ändern kann

Bei Ubuntu 11.10 ist es leider nicht mehr so einfach möglich, den System Font bzw. seine Größe zu ändern.

Auf meinem Netbook ist der Font für mich viel zu groß.

Diese Anleitung zeigt, wie man den Font ändern kann. Ist mir ein Rätsel, warum Ubuntu das nicht standardmäßig in den Systemeinstellungen möglich macht.

Howto configure additional swap file on Linux

I had to restore my linux box from a backup and I also had to configure an additional swap file. Here is a good tutorial how to do this.

Great and short tutorial about Sieve mail filtering

The Sieve mail filtering language is great for filtering email messages on the server side. 
 
I use it heavily for my IMAP account on my homeserver. There is a really good and short tutorial about the syntax with great real world examples. Go and check it out.
 
An introduction to Sieve, the mail filtering language. This tutorial introduces the basic building blocks of a Sieve filter and explains the conceps with many examples.