Monthly Archives: October 2008

Quirk Running Java as a Windows Service

I ran into a painful quirk of running a Java application server as a Windows Server service today.

The Windows Resource Kit provides a utility called “instsrv.exe” which can be used to set up another executable as a windows service. The quirk I ran into is that when you log out of your windows session, the service goes down. I need the service to stay UP.

In order to remedy this problem, the solution is to instruct instsrv.exe to start the JVM with the -Xrs option.

This option actually prevents the JMV from being terminated even when it receives the quit signal from the OS. The OS still wants to shutdown the JVM, but the JVM in effect says “no.” The OS sends a quit signal to the service which in turns passes it on to the JVM, which says “no.” So the option is being used as intended in an embedded JVM scenario (which Sun does document.)

The next step would to set up the service not to shutdown or to not pass along the quit signal to the JVM.

The only negative side effect I can think of with the –Xrs setup is that the Java application might not be exiting cleanly when it is really time to quit.

Note that –Xrs is only supported by Sun’s Java VMs. Other vendors may provide a similar option.

Importing Outlook Contacts into Gmail

This note is about correctly importing Outlook 2007 contacts into and Gmail.

A friend recently purchased the new G1 (Google Android) phone from T-Mobile and was quite disconcerted that he could not use his contacts from Outlook. All of his phone numbers were imported into Gmail as notes, which is quite useless from the G1’s point of view, since you cannot pick a contact on the phone and dial.

The problem is that Gmail’s import feature does not fully understand Outlook 2007 exported CSV files. Gmail properly imports Outlook 2003 files, not 2007. Why? Because the CSV column names have changed between 2003 and 2007.

In order for a 2007 CVS file to properly populate Gmail contacts, you must edit the column names in the CVS files and replace the 2007 names with 2003 names.

The 2003 CSV column names I got were:

"Title","First Name","Middle Name","Last Name","Suffix","Company","Department","Job Title","Business Street","Business Street 2","Business Street 3","Business City","Business State","Business Postal Code","Business Country","Home Street","Home Street 2","Home Street 3","Home City","Home State","Home Postal Code","Home Country","Other Street","Other Street 2","Other Street 3","Other City","Other State","Other Postal Code","Other Country","Assistant's Phone","Business Fax","Business Phone","Business Phone 2","Callback","Car Phone","Company Main Phone","Home Fax","Home Phone","Home Phone 2","ISDN","Mobile Phone","Other Fax","Other Phone","Pager","Primary Phone","Radio Phone","TTY/TDD Phone","Telex","Account","Anniversary","Assistant's Name","Billing Information","Birthday","Business Address PO Box","Categories","Children","Directory Server","E-mail Address","E-mail Type","E-mail Display Name","E-mail 2 Address","E-mail 2 Type","E-mail 2 Display Name","E-mail 3 Address","E-mail 3 Type","E-mail 3 Display Name","Gender","Government ID Number","Hobby","Home Address PO Box","Initials","Internet Free Busy","Keywords","Language","Location","Manager's Name","Mileage","Notes","Office Location","Organizational ID Number","Other Address PO Box","Priority","Private","Profession","Referred By","Sensitivity","Spouse","User 1","User 2","User 3","User 4","Web Page"

The 2003 CSV column names he got are:

first_name, last_name, address1, address2, city, state, zip, country,  company, email, home_phone, work_phone, cell, fax, pager, birth_month, birth_day, anniversary_month, anniversary_day

The first line of each CSV file contains the column names all on one line. I had my friend replace 2007 names with 2003 names, import the contacts into Gmail and voila, G1 dials away. For example, “first_name” must be replaced with “First Name”, “last_name” with “Last Name”, etc.

UnsupportedClassVersionError

An UnsupportedClassVersionError is thrown when the Java Virtual Machine reads a class file and version stamp in the file is not supported.

This will happen when you compile a class with a version of the compiler that is newer than the JVM you then run it on. For example, compiling a class with Java 5 and running it on Java 1.4.2 will give you an error like:

java.lang.UnsupportedClassVersionError: SomeClass (Unsupported major.minor version 49.0)

It is handy to know what version the JVM is talking about since 49.0 does not map in my brain to Java 5.

 

Java Class Version Table
Class Version
Java Version
58
14
57
13
56
12
55
11
54
10
53
1.9.0 Early Access build 107
52
1.9.0 before Early Access build 107
52
8
51
7
50
7 and 1.7.0-ea-b24
50
6
49
5
48
1.4.2
47
1.3.1
46
1.2.2

The class version is available programmatically in the java.class.version system property:

public class Test {
    public static void main(String[] arguments) {
        System.out.println(System.getProperty("java.class.version"));
    }
}