Friday, February 02, 2007

creating jni binders

1. create the java stub


package example.jni;
public class HelloWorld {
private static native void writeHelloWorldToStdout();
public static void main(String[] args) {
System.loadLibrary("HelloWorld");
writeHelloWorldToStdout();
}
}


2.compile java class

javac example/jni/HelloWorld.java


3.create the header

javah -classpath c:/clay/projects/jnitest/src/java -o HelloWorld.h example.jni.HelloWorld


4. compile the c dll

gcc -mno-cygwin -I"/cygdrive/c/Program Files/Java/jdk1.5.0_08/include" -I"/cygdrive/c/Program Files/Java/jdk1.5.0_08/include/win32" -Wl,--add-stdcall-alias -shared -o ../../dll/HelloWorld.dll HelloWorld.c


5. run it

C:\clay\projects\jnitest\src\java>java -Djava.library.path=C:\clay\projects\jnitest\dll\ example.jni.HelloWorld

"Hello World!"

cigwin/x

two points to remember:

1. Cygwin/X is installed via Cygwin's setup.exe and the installation process is documented in the Cygwin/X User's Guide. Whether or not you already have Cygwin installed, you can add Cygwin/X to your installation by downloading the latest setup.exe, running setup, and selecting the 'xorg-x11-base' package from the 'X11' category.

2. The X server, XWin, can be launched in several ways. One of these is by running c:\cygwin\usr\X11R6\bin\startxwin.bat (you may wish to create a desktop shortcut to this batch file so that you can launch the X server by clicking on its icon). Another way to launch the X server is by running the command startx in a Cygwin window.

Tuesday, January 30, 2007

terrible bug

well this bug at work is totally getting to me. I have been hammering on it for days and it seems to keep popping back up. it is really demoralizing because I thought I had it, and then I did an update and it f'n came back.

basically I am inventing a new way to do transactions because the original implementation put data in multiple databases. this model requires multiple session factories to be concurrently managed. not an easy task. not to mention I havent ebven started to figure out resource management.

so to make this possible i have to create my own transaction manager that intercepts the datasource id to do a lookup of the appropriate session factory to use.

I am really at wits end. I think I can figure it out, it just is so painful to hammer my head against the wall day after day.

command line mysql with sql logging

mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 4.1\my.ini" --log="myhost.log"

The little detail is that the log command must be after the defaults file.

dont ever use classpath application context in a web application

the architect before made a pretty big mistake by using the class path application context for spring. it caused tons of problems. He created a static bean factory so anyone could just get any old bean anywhere in the code. Not only is this a problem from a cross context point of view but developers also starting making direct factory calls in the code, totally bypassing the whole dependency injection model.

generally I would recommend only using class path application context for unit tests or stand alone applications.

Saturday, January 27, 2007

The best article on integrating Spring and Struts

This article is awesome, it is probably the best article on integrating Spring and Struts I have found. Specifically i recommend recipe3.

Get a better handle on Spring