Friday, February 10, 2006

BufferedImage needs Display under Unix

problem:

java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.

solution:

set java.awt.headless=true
System.setProperty("java.awt.headless","true");

unless your system needs a gui, then, you need to google.

Thursday, February 09, 2006

A cool function

I wish i saw this when i had to do java homework, it would have helped.
to bad i never had to since reverse any numbers.

Wednesday, February 08, 2006

RMI on UNIX problems

so now that i have my server running on Freebsd, there is a slew of related problems:

i got this on the client:

RMI connection refused problem solved.
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect

when i was connecting to the bsd server which isnt localhost by the way, the error seems to stem from the way i have my hosts file setup on bsd, and a quick solution is to include the following code when launching the server:

-Djava.rmi.server.hostname=YOUR_SERVERS_IP

that fixes everything.

another problem im getting now has to do with BufferedImage. apperantly BufferedImage requires a screen to draw its image on. and i dont have one, when i shell into the system. i get this error:

java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.

Solution will be presented when i find it.

RMI is pretty evil

new problems and their solutions:

any time you get an exception having to do with marshaling and you know that you have not changed any of your stubs, then its a codebase error! to fix:

System.setProperty("java.rmi.server.codebase","http://website.com/codebase/");
into that directory you can put your stubs, tho there is a little catch there. you have to put them in like this
http://website.com/codebase/package1/subpackage/Class_Impl_Stub.class
if the fully qualified name ofr Class_Impl_Stub is package1.subpackage.Class_Impl_Stub

people on the interweb say that using an http address is less troublesome then trying to use a file:// url

also, put your policy file into the same directory as your main jar file.

here is a good command line example of how i start my server:
>rmiregistry&
>java -Djava.rmi.server.hostname=134.88.14.133 -Djava.rmi.server.codebase=http://website.com/mk/codebase/ -Djava.security.policy=./policy.all -jar server.jar

note that server.jar contains a manifest file that points to all the libs it needs.

your client app should also have this codebase declaired obviously.