Friday, June 4, 2010
Windows Server 2008 R2 Server Core as a Print Server
Thursday, March 18, 2010
Multiple Grails Apps on a single App Server
Background
Historically I've used Glassfish v2 for hosting many of my Java Web Apps. Lately I've been developing in Grails When it comes to deploying these applications on a production server, the memory requirements are a bit higher than simple JSF applications. Once I had deployed a half dozen or so Grails apps to my production server strange things started to occur such as applications suddenly stopping. I eventually tracked these down to Perm Gen, and Heap memory errors. Through this process I learned that I hate Glassfish's log files (or lack there of).
Goals
A dedicated Tomcat 6 server to host my Grails apps.
The "Hardware"
This server will be a multi-core machine with 4GB of RAM. I'm running it as a VMware virtual host, but a physical machine won't be too different.
The Operating System
Start with the Ubuntu Server 9.10 64-bit install ISO
For most of setup, the standard answers apply except where noted.
Because the host is a virtual machine, at the boot loader screen I choose to hit 'F4', and selected "Install a minimal virtual machine" as the setup type.
For disk partitioning, I always use LVM.
When the installer gets to the "Software Selection" screen, enable OpenSSH Server, and Tomcat Java Server
Tomcat Settings
Pay close attention to this section. This is where you need to configure your memory setting appropriately. Most grails applications need at 64 MB of PermGen space each, and somewhere around 64-128MB of
Add the following options to /etc/defaults/tomcat6
# change the default garbage collector
TOMCAT6_SECURITY=no
# Tell the JVM we're "headless"
JAVA_OPTS="-Djava.awt.headless=true"
# Set the Memory Pool Size
JAVA_OPTS="$JAVA_OPTS -Xms2048m -Xmx2048m"
# Set the PermGen Size
JAVA_OPTS="$JAVA_OPTS -XX:PermSize=1024m -XX:MaxPermSize=1024m"
# change the default garbage collector to
# The "recommended" garbage collector for Web Servers
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"
Remote Management
Setup Tomcat Users so you can use the manager app by editing /etc/tomcat6/tomcat-users.xml
<tomcat-users>
<role rolename="admin">
<role rolename="manager">
<user username="yourusername" password="SecretPassword" roles="admin,manager">
</tomcat-users>
Monday, February 15, 2010
Grails and MS-SQL Server
This is because the MSSQL server Dialect is designed to support MSSQL Server versions older than 2000. MSSQL Server 2000 and later has support for BIGINTs, and therefor doesn't need to store it's primary keys in numeric columns.
The fix for this is to create a new SQL Server Dialect for SQL Server 2000 and later. We do this by creating the following file in our Grails project
src/java/org/hibernate/dialect/SQLServer2000Dialect.java
Containing the following code
package org.hibernate.dialect;
import java.sql.Types;
public class SQLServer2000Dialect extends SQLServerDialect {
public SQLServer2000Dialect() {
super();
registerColumnType(Types.BIGINT, "bigint");
registerColumnType(Types.BIT, "bit");
}
}
Then we edit our DataSource.groovy that's located under grails-app/conf so that it uses our new dialect.
dialect = "org.hibernate.dialect.SQLServer2000Dialect"
And wala! Our primary keys are bigints!
What this also means is that grails will also set the primary key to be identity columns rather than the not quite as useful hilo algorithm.
Thursday, February 4, 2010
Grails and Date Inputs
I've been rather frustrated with the datePicker input tag for grails lately. For anyone who writes software for people who do data entry 8 hours a day, 5 days a week, you know that picking a date from pull-down menus, or via a calendar navigation such as the calendar plugin for grails is a huge waste of time and very slow.
To resolve this I've taken the approach of using textInput tags for the dates
<g:textfield name="birthDate" size="12" maxlength="10" value="${personInstance?.birthDate?.format('MM/dd/yyyy')}" class="datePicker" />
And using jQuery UI to add a calendar control to the inputs so that if the user wanted to, they can use a datePicker
// Turn all textFields of class 'datePicker' into jQuery.UI.calendar controls
jQuery(document).ready(function(){
jQuery('.datePicker').datepicker({
showOn: 'button',
buttonImage: '/myapp/images/calendar.gif',
buttonImageOnly: true });
});
Then, because the default date format for text inputs in grails is yyyy-mm-dd hh:mm:ss, which is not the most common format entered for dates in my demographic (US), I added a customPropertyEditorRegistrar in grails-app/conf/spring/resources.groovy
beans = {
customPropertyEditorRegistrar(util.CustomPropertyEditorRegistrar)
}
and then in src/groovy/util/CustomPropertyEditorRegistrar.groovy
package util
import java.util.Date
import java.text.SimpleDateFormat
import org.springframework.beans.propertyeditors.CustomDateEditor
import org.springframework.beans.PropertyEditorRegistrar
import org.springframework.beans.PropertyEditorRegistry
public class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Date.class,
new CustomDateEditor(new SimpleDateFormat("MM/dd/yyyy"), true));
}
}
And then I'm happier, and the data entry staff that need to use my applications are happy.