Posts

Eclipse Crashing During starting up

I have experienced several issues of eclipse crashing with workspace configured. It would generally take lot of time and will simply display the splash screen. Initially I thought it is due to lack of memory(RAM), but I saw similar symptoms even with massive configuration(16GB Ram, Quad Core etc) After googling I found the actual cause of eclipse crashing, The solution is simple, delete specific .snap file from eclipse workspace location. For me deleting the following files worked, \.metadata\.plugins\org.eclipse.core.resources\.snap   and \.metadata\.plugins\org.eclipse.core.resources\.root\.markers.snap Eclipse uses .snap files for remembering workspace state during runtime. Deleting these files' does not effect any projects in the workspace, every thing for me just worked fine.

JDOM Parser to Read and Update XML

JDom is a java based library for processing XML.  It is light weight and fast. It is simple to use since it was designed for Java. JDom Documents can be used with DOM tree or SAX events. JDom Support XPath. The following examples shows some common usecases with JDom such as 1) Update the value of a node in the xml 2) Print the xml from JDom Document 3) Get a particular Node using XPath //Update the value of a node Document doc = new SAXBuilder().build(new File(fileToProcess)); Element rootElement = doc.getRootElement(); Element book = rootElement.getChild("book").getChild("author") .setText("Sidd"); //Print the xml XMLOutputter outputter = new XMLOutputter(); outputter.output(doc, System.out); // Get a particular Node useing XPath XPath xPath = XPath.newInstance("/bookstore/book[bookid=$bookid]/bookid"); xPath.setVariable("bookid", "id1002"); Element guest = (Element) xPath.selectSingleNode(doc); System.out.pri...

Eclipse plugin for maintaining copyright text in source code

Wondering how to maintain copyright or disclaimer text on source files. Specially when you have a number of files in your project, and you probably want to add some sort of info text or say copyright text as header in each and every file. Recently I found a easy simple to use eclipse plugin  http://www.wdev91.com/update/  which can be used easily to add or even replace existing header information text from source files. Since adding the text in each file is manually is very error prone and takes lots of effort, this plugin is very useful. You can find more information here  http://www.wdev91.com/

Failed to load or instantiate TagLibraryValidator

Problem Usecase: Downloaded the Apache Tag libraries and copied them in the web-inf /lib/jstl-libs/ folder. Included the taglib directory in jsp page, compiled and deployed in Tomcat 6. During runtime got the following exception. Exception Details [Truncated]: org.apache.jasper.JasperException: Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51) org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409) org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:281) org.apache.jasper.compiler.TagLibraryInfoImpl.createValidator(TagLibraryInfoImpl.java:670) org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:249) org.apache.jasper.compiler.TagLibraryInfoImpl. (TagLibraryInfoImpl.java:164) org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:386) org.apache.jasper.compi...

Linux Reference Page

##Finding particular text in files Find all the *.java files which contains the string confirmStatus in directory src (relative to the current directory). command$  find ./src -name \*.java | xargs grep -il 'confirmStatus' find commands searches list of files and passes the list to xargs, which in turns split the list and passes the each file name as argument to grep command. ##Change Domain password from Linux smbpasswd -r -U ## Setting up Printer in Ubuntu Linux $ gksudo system-config-printer ## Mounting Share drive in Guest Ubuntu Oracle Virtual Box To mount a shared folder say C:\MyVideos as MySharedVideos sudo mount -t vboxsf  MySharedVideos   /media/siddshare2 where  MySharedVideos  is the shared folder name and /media/siddshare2 is the mount point location. ##  Printing all contents to a single line Where myfile.txt contains some text data which we want to print in a single line. cat myfile.txt | tr -d '\n' > oneline.txt...

JSON Manipulation in Java

JSON stands for Java Script Object Notation, in which essentially we represent data in name:value pair in a string. Example of JSON strin is as follows {    "lastName":"Smith",    "suffix":"Jr",    "city":"Foster City",    "country":"US",    "postalCode":"94404",    "firstName":"John" } Which represent the Data about a user. JSON is a standard notation to exchange data. To process Json String , like converting from Json String to Java or vice versa we have so many different libraries in Java.One of the Most prominent being Jackson, Bellow are the example or Some Use cases for Handling Json in Java. Converting JSON String to Java Object Using Jackson We can use ObjectMapper to convert a JSON String to java Object. ObjectMapper mapper = new ObjectMapper(); UserInfo userInfoObj = mapper.readValue(JSONStringSrc,  UserInfo.class); Where UserInfo Obje...

String Manipulation in Java

Working with String like things in java is very common, and one of the common uses case. While we need to replace a substring inside a long String, we have couple of options in java. Java "String" itself has methods like replace and replaceAll which we can use to replace a substring from the main string. The other option is using StringBuilder  which has method like replace(start, end,str);   Which is better then the formar and we will see the difference in details next. We can also use Pattern and Matcher to replace substring from String like bellow. Pattern p = Pattern.compile(" \\$\\{USERNAME\\ }"); Matcher m = p.matcher(ORIGINAL_STRING); p = Pattern.compile(" \\$\\{USERNAME\\ }"); m = p.matcher(ORIGINAL_STRING); m.replaceAll(USERNAME_VALUE); But the for most of the cases much better and efficient way to replace substring is to use Apache StringUtils Utility Class. I have created some test methods which utilizes the above mentioned dif...