Java

Going off-heap to improve latency and reduce AWS bill

Great read - shows you the power of Java and Chronicle Map. Describing how going off-heap with the help of Chronicle Map helped us to get rid of the latency hiccups and cut our Amazon AWS bill in half. Source: Going off-heap to improve latency and reduce AWS bill – Plumbr Caution: Before you go diving into using the open source version of Chronicle Map, there are some gotchas to be aware of from a features point-of-view.

Developing email applications on Windows, targeted for Linux environment - email, mailx, sendmail

If you’re developing on a Windows platform for an application targeted for Linux or Unix that deals with email, then this article will be useful. Let us begin by understand the problem. Problem If you are a Java/Spring developer, (developing in Java is platform independent - runs on any platform where a JVM is available) then you have two options in front of you for sending emails from a Java application:

Grails No profile found for name [web] illegalstateexception

Most likely you’ve landed on this page because you’ve searched for the error in a search engine and it brought you here. Symptom: When you run “grails” under an existing project that you previously had (either on a different PC or from a source-control like GIT or SVN and you’ve mistakenly included the “build” directory). The associated error would have been one of the following: Grails No profile found for name [web] or java.

Grails 2.3.5 - grails stop-app - does not stop the app running via run-app

If you’re using Grails 2.3.X and you’re developing, most likely you’re running your app like this: [sourcecode language=“jscript”] grails run-app #in one command-prompt/shell-terminal and grails stop-app #in another command-prompt/shell-terminal [/sourcecode] With the latest version of Grails (version 2.3.5), the stop-app say: [sourcecode language=“jscript”] grails stop-app | Server Stopped But nothing happens and the server-process continues to run# [/sourcecode] Here’s an undocumented fix that can come in handy: [sourcecode language=“jscript”] On terminal/command-prompt #1 Run the way you do today grails run-app

Grails - Adding JavaScript to bottom of page

In Grails using the templating (Sitemesh) if you were to include per-page JavaScript resources then it shows up much earlier in the layout content as part of the <g:layoutBody> Here is an example illustrating the problem: SamplePage.gsp [sourcecode language=“html”] MyThinkPond.com Custom Page ... Some this page content [/sourcecode] and the layout page (layoutPage.gsp) [sourcecode language=“html”] ... Some template (header) content [/sourcecode] results in the following page in browser [sourcecode language=“html”]

Grails 2.X .gitignore file

With a new Grails 2.X project you run into challenges on which folders to check-in into a GIT repository. You want to remove any non-essential files that Grails can rebuild at run-time. And if you are using either GITHub or BitBucket for your GIT repo’s the default .gitignore file created or provided by GITHub is setup for configured for a Grails 1.X project and not a Grails 2.X project.

Working with zeromq (0mq), Java, JZMQ on a CentOS platform

Recently I decided to port some of my development using ZeroMQ onto my CentOS development machine and I ran into some challenges. I’m documenting those challenges so that if someone else runs into the same pitfalls I did, they can avoid it. In this example today, we will work with the first “HelloWorld” examples in the ZeroMQ guide found here. I added a few modifications to the sample such as a package name and a try-catch around the Thread and an exception.

Java Tools for Source Code Optimization and Analysis

Below is a list of some tools that can help you examine your Java source code for potential problems: 1. PMD from http://pmd.sourceforge.net/ License: PMD is licensed under a “BSD-style” license PMD scans Java source code and looks for potential problems like: Possible bugs - empty try/catch/finally/switch statements Dead code - unused local variables, parameters and private methods Suboptimal code - wasteful String/StringBuffer usage Overcomplicated expressions - unnecessary if statements, for loops that could be while loops Duplicate code - copied/pasted code means copied/pasted bugs You can download everything from here, and you can get an overview of all the rules at the rulesets index page.

Not all Tomcat 6 classloaders must be equal

Today, while doing some Grails development I came across a peculiar issue that perplexed me and I’m documenting it for all others to benefit. (Also see my other blog from today for the issue that started this journey). Here are my specifications: Development Machine Windows-7, 64-bit java version “1.6.0_24” Java(TM) SE Runtime Environment (build 1.6.0_24-b07) Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode) Grails 1.4.0.M1 Tomcat - apache-tomcat64-6.0.32 Local Deployment Server

Tomcat 6+: Infamous "SEVERE: Error listenerStart" message - How-To debug this error?

I’m sure if you have been developing with Java and Tomcat for sometime, you are likely to run into the infamous debug error. SEVERE: Error listenerStart You will most likely start Googling it trying to find out what the heck is going on. And in trying to see the extended logging on what that “listenerStart” error means. After some lucky searches, you will see links asking you to drop a “log4j.

How-To: Change Grails User work and cache directory under windows

The directions below will help you move the Grails user work and cache directory to a different location. Why? Sometimes your default “primary drive” may be running out of space and you need to move your workspace else where. How? Create a file called “settings.groovy” under “C:/Users/.grails” directory. Edit this file and add the following line: [sourcecode language=“jscript”] grails.work.dir=“D:/grailswork” [/sourcecode] Make sure that the defined folder exists. Remove all other content, files and folders in the “.

Understanding Tomcat Configuration

Case #1: When the Tomcat config is this: [sourcecode language=“jscript”] [/sourcecode] Observe the “path” element in the “Context”. Then… http://localhost/index.jsp yields to the “index.jsp” under HelloWorld folder. http://localhost/HelloWorld/index.jsp yields to a “404 Page”. Case #2: When the Tomcat setup is this: [sourcecode language=“jscript”] [/sourcecode] Once again observe the “path” element in the “Context”. Then… http://localhost/index.jsp yields to a “blank page”. http://localhost/HelloWorld/index.jsp yields to a “blank page”. http://localhost/hw/index.jsp yields to the “index.

Add custom jars under "\WEB-INF\lib" in a Maven project

The answer is a lot simpler than you think. But before we explore the answer, I should warn you that this approach is not what is recommended by Maven. Maven builds upon consistency and structure and this process goes away from that methodology. In Maven, you can take each of your jars\libraries and add them to your local repository and then include them as needed in your projects. If you want to go the proper route here’s how you do it.

Weblogic 10.3 Heap Size (does not allow 3072mb)

Has anyone experienced a similar issue? In tuning Weblogic 10.3 R27.6.0-50 for Windows, we were trying various values for the heap size. Startup jRockit options: [sourcecode language=“jscript”] -Xms1024m -Xmx1024m [/sourcecode] We were setting both values to the same. 1024m = worked 2048m = worked 3072m = did not work 4096m = worked Did anyone experience a similar problem in allocating? Is there something special about 3072MB? Update from Sept. 28th, 2010: When we tried this additional property in the start-up parameter the 3GB option works: -XxcompressedRefs=0

Maven - GWT - Vaadin - including additional custom jars in a maven project under "\web-inf\lib"

With a lot of folks trying Google Web Toolkit (GWT) and\or Vaadin (combined with Maven), one of the problems that they might encounter is this: How do I get my custom Vaadin themes or GWT jar files included under my "\web-inf\lib" folder inside the war Here’s a link to the such a question in detail. The answer is a lot simpler than you think. But before we explore the answer, I should warn you that this approach is going away from what Maven would like you to do.

GWT and Spring Integration - java.net.InetAddress is a restricted class

When trying to integrate both Spring and GWT, one might encounter the following error in the Spring Eclipse IDE: “java.net.InetAddress is a restricted class”. The problem happens when you try to use Spring configuration for your database. In my case, I was using Spring to update data back to a H2 database. Well, here’s one way to deal with this issue. Disable the “Google App Engine”. Yes, based on my research, if you’re using GWT, you can disable Google App Engine and still continue your development with GWT.

JBoss AS6 - Failed to resolve schema nsURI= location=persistence

If you encounter the following error when deploying under JBoss AS6: “Failed to resolve schema nsURI= location=persistence” The chances are that you are missing the name-space for the persistence.xml file. So examine your persistence.xml file and replace the tag with the following: [sourcecode language=“jscript”] [/sourcecode] And this should help you get rid of the above error. cheers.

Weblogic 10.3 - Using clear passwords while in production mode

In Weblogic, (on your development server or workstation), you might want to run it in “production mode” but you don’t want to go through and encrypt all the database passwords in the JDBC files for your development database servers. Well, this article shows you how. Before you do this, make sure you are NOT doing this in a production environment. By doing this in a real-production environment, you may be compromising the security of your production infrastructure.

Notable difference between Apache Ant 1.7.x and 1.8.x - path and pathelement

On key notable difference I’m observing between Apache Ant 1.7.1 and 1.8.1 is with the path and pathelement. a build.xml file before =========================== If you had a path-id set in a target that may never get executed, Ant will make an attempt to find that path and use it. Whereas with 1.8.1, you will need to move those “Init” properties to the main level so that they will be properly found and used.

Spring Framework Samples and Reference Implementations online in svn

Sometimes it’s good to look at the svn repository for the reference sample that Spring Framework provides. Here’s a quick link for that URL: https://src.springframework.org/svn/spring-samples/ You can traverse through it via a HTTP(s) browser or you can download the latest samples via tools like TortiseSVN. Here is a list of some of the projects samples that are available today: spring-samples - Revision 431: / * configuration-basic/ * jpetstore/ * mvc-ajax/ * mvc-basic/ * petcare/ * petclinic/ * petclinic-groovy/ * spring-travel/ * task-basic/ * templates/ * tutorials/ Hopefully this article will be beneficial for someone who is trying to get familiar with Spring Framework.

Java 6 Gems: Spash Screen for your application

In my coverage of all the new features that are part of Java SE 6, there is a new gem added that makes the user experience very clean and concise when you bring up a web-start or applet or desktop based Java application. Namely, the splash screen. When you load up a native application, it’s very traditional to display a “splash screen” with the company logo and branding of the particular product.

Java 6 Gems: Scripting Framework to support Rhino Javascript and Groovy (natively)

What is it? With Java 6 there is a new addition (package: javax.script) that allows you to work with scripting languages like Javascript (using Rhino) and Groovy. Although there is built in support for adding scripting engines like Groovy, PHP, Perl, etc - what’s bundled in this release is Mozilla’s Rhino Javascript Engine. Why embed a scripting language? Most scripting languages out there are dynamically typed. Meaning, your code does not need to know what type of value you will be storing in a particular field at compile time.

Speeding up your load time for your Java applets and webstart applications

Today we are going to look at a new feature available in Java 5 and above that can speed up your load time of your jar’s within your applets and web start (provided you have a web server that’s hosting the jar that’s HTTP/1.1 compatible server). Let’s first take a look at what happens on the back-end: In a typical applet (same applies to a web-start application), you have a src/source tag that points to a JAR file like this:

Commonly overlooked feature in Java 5 - varargs

Today I’ll comment on a commonly overlooked feature now available in Java (since Java 5.0) called “varargs”. How many times have you done this? [sourcecode language=“jscript”] public ConstructorOne(String personFullName){ // Does something } //and later on added another constructor that took another parameter public ConstructorOne(String personFirstName, String personLastName){ // Now breaks down the name to pass along two strings instead of one. } // and so on… [/sourcecode] Well, not anymore.

Forwarding to a URL from Wicket

Sometimes we need to forward to a servlet or resource that’s outside of Wicket such as a servlet. Here’s how: Modify your web.xml to define your servlet as well as your Wicket application “ignorePaths” init-param: [sourcecode language=“xml”] Wicket Example MyApplication org.apache.wicket.protocol.http.WicketFilter applicationClassName com.gu.MyApplication wicket.configuration deployment ignorePaths images/,s/ MyApplication /* SomeServlet com.gu.SomeServlet SomeServlet /s/koolkat.do [/sourcecode] The first observation is that Wicket is running as a Filter and not a Servlet.