Friday, July 25, 2008

I think I found a bug in JBoss Native

With the VPC usage on deployment testing is becoming a common practice, software bug can be traced more easily, and more important, early.

When involving in company project that uses the JBoss Application Server, I found a strange behaviour in JBoss. I install of the necessary Java installers and eventually I could not start my window service, using JBoss Native.
This is the way you can simulate.

1) Download VPC 2007 and Windows XP virtual harddisk to re-test, can be obtained here free from Microsoft (valid till September 2008):

2) Install JDK & JRE from Sun Java, using default path ( I used jdk1.5.0_15 Windows x86) without restart PC.

3) Configure JAVA_HOME system variables:

4) Install Ant at C-drive ( I used apache-ant-1.7.0) and configure ANT_HOME system variables:

5) Install JBoss at C-drive ( I used jboss-4.2.2.GA):

6) Run the "run.bat" in the "%JBoss_HOME%\bin" directory to verify everything is installed properly. Go to IE and type: http://localhost:8080/jmx-console/

6) Shut down the JBoss in step(5) by pressing Ctrl-C. Install JBoss Native (I used JBoss Native 2.0.4 Win32 x86), even using a new command prompt.

7) run "service.bat install" in command prompt from "%JBoss_HOME%\bin" directory:

7) run "net start JBAS50SVC", you will hit error here.

8) Open "run.log" produced in "%JBoss_HOME%\bin" directory and you will see this:

Starting JBoss Application Server 5.0 [2008-07-24 04:18:06]
ECHO is off.
JAVA_HOME is not set. Unexpected results may occur.
Set JAVA_HOME to the directory of your local JDK to avoid this message. ===============================================================================
JBoss Bootstrap Environment
JBOSS_HOME: C:\jboss-4.2.2.GA
JAVA: java
JAVA_OPTS: -Xrs -server -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000
CLASSPATH: C:\jboss-4.2.2.GA\bin\run.jar
Error: no `server' JVM at `C:\Program Files\Java\jre1.5.0_15\bin\server\jvm.dll'. Shutdown JBoss Application Server 5.0 service [2008-07-24 04:18:07]

And I reported this strange behaviour (or could be bug) to JIRA (kinda JBoss version of BugZilla), and update the JBoss Wiki :)

Tuesday, July 15, 2008

How to capture the output from Console.WriteLine

Sometimes, windows/console application needs to capture the output from console.writeline for debugging purpose. It's useful if the application can run in verbose mode, so that we can know at which point the system crashes. Maybe you might think we can implement ConsoleTraceListener Class in .Net 2.0.

While doing some tutorials on Linq on .Net 3.0, I found the sample have another simpler way to achieve that. Here are the steps:

1) Create a windows application

2) Design a simple GUI. Button represents you business logic and multiline textbox means the trace information.

3) Set the StreamWriter to the Console output, re-capture it with TextWriter will do.

Imports System.IO

Public Class Form1
Private ReadOnly _OutputStreamWriter As StreamWriter = New StreamWriter(New MemoryStream())

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Capture console output
Dim writer As StreamWriter = _OutputStreamWriter
Dim oldConsoleOut As TextWriter = Console.Out
Dim stream As MemoryStream = CType(writer.BaseStream, MemoryStream)

' set to result pane
TextBox1.Text += writer.Encoding.GetString(stream.ToArray())

End Sub

Private Sub DoSomething()
Console.WriteLine("Hello world!")
End Sub
End Class

4) Here's the final result: