Saturday, April 11, 2015

Spring Tool Suite crashes at start up on debian wheezy

At the time of starting spring tool suite on debian wheezy crash occurs with the below log:

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
org.eclipse.m2e.logback.configuration: The org.eclipse.m2e.logback.configuration bundle was activated before the state location was initialized. Will retry after the state location is initialized.

(java:7096): GLib-GObject-WARNING **: cannot register existing type `GdkDisplayManager'

(java:7096): GLib-CRITICAL **: g_once_init_leave: assertion `result != 0' failed

(java:7096): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed

(java:7096): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(java:7096): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed

(java:7096): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(java:7096): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed

(java:7096): GLib-GObject-WARNING **: cannot register existing type `GdkDisplay'

(java:7096): GLib-CRITICAL **: g_once_init_leave: assertion `result != 0' failed

(java:7096): GLib-GObject-CRITICAL **: g_type_register_static: assertion `parent_type > 0' failed

(java:7096): GLib-CRITICAL **: g_once_init_leave: assertion `result != 0' failed

(java:7096): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f342ddc273f, pid=7096, tid=139862722598656
#
# JRE version: Java(TM) SE Runtime Environment (8.0_40-b25) (build 1.8.0_40-b25)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.40-b25 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libgdk-x11-2.0.so.0+0x5173f] gdk_display_open+0x3f
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
#/springtoolsuite/sts-bundle/sts-3.6.4.RELEASE/hs_err_pid7096.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#


Debian wheezy comes with glibc 2.13. For eclipse in gtk3 we need the minimum version to be 2.14. To resolve the problem please upgrade the glibc version to 2.14.

Another work around is there. We have to force STS to always use GTK2. This would be the easiest to get STS up without crash. To force STS to always use GTK2, we need to include few lines in STS.ini file. Just add the following lines:

--launcher.GTK_version
2

In my case STS.ini file is as below:

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20150204-1316
-product
org.springsource.sts.ide
--launcher.defaultAction
openFile
--launcher.GTK_version
2
-vmargs
-Dosgi.requiredJavaVersion=1.8
-Xms40m
-Xmx768m
-XX:MaxPermSize=256m






Wednesday, August 20, 2014

Installing tomcat7 on ubuntu


Follow the steps to install tomcat7 system  wide but before that install java.
Open a terminal by Ctrl+Alt+T

1.Run the following command to install tomcat7
   sudo apt-get install tomcat7
 
   This command will install tomcat7 with default settings under ROOT. Then open a browser and     go to  http://localhost:8080/ . A defualt page will display "It works..." .

2. Install tomcat documentation by the following command
    sudo apt-get install tomcat7-docs

3. Install web apps to administer tomcat server
    sudo apt-get install tomcat7-admin

4.Now to access manager webapp and the host-manager webapp page (This link will be there at     "It works" page). username and password is required. To set username and password centrally

    sudo su
    sudo gedit /etc/tomcat7/tomcat-users.xml
  
    Above command will open a text editor. Then find the following lines in that editor
            <tomcat-users>
               ..........
            <tomcat-users/ >
           
    Then inside this tag put the following lines:
             <user username="admin" password="admin" roles="admin-gui,manager-gui"/ >
     use your own username and password.
   
     To get the effect now restart the tomcat service by the following command
     sudo service tomcat7 restart
     
     After completing this task use the username and password when authentication pop up comes.
     This will let you administer the tomcat through web interface.

5.  If it is required to change the HTTP connector port which is by default 8080 to avoid conflict
     sudo gedit /etc/tomcat7/server.xml   
     Above command will open a text editor. Now find the following lines and change the port 8080 
     to the desired one.
               <Connector port="8080" protocol="HTTP/1.1"
                    connectionTimeout="20000"
                    URIEncoding="UTF-8"
                    redirectPort="8443"/ >
     
     To get the effect now restart the tomcat service by the following command
     sudo service tomcat7 restart
 
     Now open a web browser and go to http://localhost:yourport/ . "It works".... will be displayed.
      

Monday, August 11, 2014

How to fix xdoclet 1.2.3 failure when generics is used in EJB?

XDoclet is a tool to generate necessary interfaces and EJB deployment descriptors for the beans.

XDoclet1.2.3 can not generate ejb deployment descriptor and interfaces for the bean if generic is used in the bean. It happens due to lack of generic support in XDoclet1.2.3 . If generic is used in the beans then at the time of running XDoclet1.2.3 it shows error like below:


[ejbdoclet] (XDocletMain.start 47 ) Running

[ejbdoclet] Generating EJB deployment descriptor (ejb-jar.xml).
[ejbdoclet] Error parsing File D:\panacea-workspace\Panacea_Entity\PanaceaEJB\ejbModule\panacea\ORS\ejb\eoutremBO.java:Encountered "<" at line 99, column 26.
[ejbdoclet] Was expecting one of:
[ejbdoclet] ...
[ejbdoclet] "[" ...
[ejbdoclet] "." ...
[ejbdoclet] "(" ...

[ejbdoclet]    

XDcolet 2 has generic support. But for XDoclet1.2.3 to avoid the above error just follow the following steps :

Go to your XDoclet1.2.3 directory. Then go to lib folder. There is one jar named xjavadoc-1.1.jar. Just replace the jar with xjavadoc-1.5-snapshot050611.jar. The jar can be found here http://sourceforge.net/projects/xdoclet/files/xjavadoc/1.5-snapshot050611/  

Now run XDoclet 1.2.3 and use generics and XDoclet1.2.3 without failure.

Saturday, August 2, 2014

How HashSet determines duplicate object?

When one object is put in the HashSet, it checks whether its already having any object with the hashcode matching the one that it is going to be put. If no matching hashcode found it assumes that this one is not a duplicate. If HashSet finds a matching hashcode for two objects- one that is going to be added and one already in the set-the HashSet will then call one of the object's equals() methods to see if these hashcode-matched objects are really equal. And if they are equal then it treats the object as duplicate. 

For String,Integer etc are having their own overriden hashCode() and equals(Object) methods for which its not possible to add two duplicate String or Integer in the HashSet. 

If instances of your own made class are the elements of set then definitely its important to define the case which will determine whether the two instances are identical or not through overriding the hashCode and equals method.

Lets do some coding to get the idea more clearly: Suppose we want to make a set of Books. Where we want to treat two instances of Book will be duplicate if they have the same title. We will achieve this by overriding the hashCode and equals method. Then we will try to add the two objects having the same title in the Set.
Book.java
public class Book{
 private String title;

  public Book(String title) {
  super();
  this.title = title;
 }

  public String getTitle() {
  return title;
 }

  public void setTitle(String title) {
  this.title = title;
 }

  @Override
 public String toString() {
  return getTitle();
 }

  @Override
 public int hashCode() {
  return getTitle().hashCode();
 }

  @Override
 public boolean equals(Object object) {
  Book anotherBook = (Book) object;
  return this.getTitle().equals(anotherBook.getTitle());
 }

}
In the above book class notice the two hashCode and equals method. We took the help of String class's equals and hashCode method. As our title is String so we can take the help of hashCode and equals method of String class. That means if two titles are same then it will provide the same hashCode and equals method will also return true. 
TestSet.java
public class TestSet {
 public static void main(String[] args) {
  Book one=new Book("A");
  Book two=new Book("B");
  Book three=new Book("C");
  Book four=new Book("D");
  Book five=new Book("D");
  Set<Book> bookSet=new  HashSet<Book>();
  bookSet.add(one);
  bookSet.add(two);
  bookSet.add(three);
  bookSet.add(four);
  bookSet.add(four);
  bookSet.add(five);
  System.out.println(bookSet);
 }
}
If the above code is run then the output will be : [D, A, B, C].

See the output doesn't contain the D twice. But we added D twice.

Now just comment the hashCode and equals methods of Book.java. And run the TestSet.java. 
Now the output is : [D, D, B, C, A]. 

What happened?
As in Book class we have commented the equals and hashCode method so equals and hashCode method from the Object class will be called. Because implicitly every class extends the Object class.

"The default behavior (from Object) is to give each object a unique hashcode value. So you must override hashCode() to be sure that two equivalent objects return the same hashcode. And the default behavior of equals method is to do an == comparison. So if you dont override equals method no two objects can ever be considered equal since reference to two different object will always contain a different bit pattern. So you must also override equals(Object) method so that if you call it on either object. passing in the other object, always returns true."
As we are treating two different object as equal if both of them have same title. So we must override hashCode and equals method.