Tuesday, October 20, 2009

Blogger : Syntax highlighting for code

I hate the way Blogger displays code , XML etc, inside the "blockqoute" construct.

Then I came across this:

How to add syntax highlight to Blogger.

This uses Syntax Highlighter.

Just to add:

You don't need to host the files. You can use:

http://syntaxhighlighter.googlecode.com/svn/trunk/

e.g. the link in the article would become:
http://syntaxhighlighter.googlecode.com/svn/trunk/Styles/SyntaxHighlighter.css

Update: As per the comment:

More info. available here:
http://mlawire.blogspot.com/2009/07/blogger-syntax-highlighting.html

Warning: There are a number of posts around on how to do this - all slightly different - use at your own risk.

Enjoy!

Log4J : Path to properties file

For Glassfish, we normally put the log4j.properties in the "domain / config" directory.

To enable Glassfish to find it, add the following to the Glassfish JVM settings. Easiest way is to use the Admin console i.e. Application Server / JVM Settings / JVM Options.

Add this line:

-Dlog4j.configuration=file:///${com.sun.aas.instanceRoot}/config/log4j.properties

Enjoy!

Netbeans : Generating getters and setters for a Java class

Using Netbeans 6.5.

Unlike Eclipse (where the link to do this is obvious), in Netbeans you will find this under:

Refactor / Encapsulate Fields

Enjoy!

Metro : JAX WS catalogue

One of the problems with using Netbeans to generate web services using Glassfish / Metro is that when you want to create a new Web service client, you are asked to select the web service which is normally on your local machine.

This means that the web service has an address like http://localhost:8080 and it then becomes a problem when you deploy to other environments.

One way around this is to use a catalog to resolve the addresses at run time. The file is called jax-ws-catalog.xml and it's placed in the META-INF directory.

It looks like e.g.

 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
<rewriteSystem
systemIdStartString="http://localhost:8080/"
rewritePrefix="http://some url:some port/"/>
<rewriteURI
uriStartString="http://localhost:8080/"
rewritePrefix="http://some url:some port/" />
</catalog>


This searches for any URL that starts with "http://localhost:8080/" and replaces this with "http://some url:some port/" e.g.

http://localhost:8080/webserver/WebService

becomes

http://some url:some port/webserver/WebService

The ant build files in Netbeans use the -catalog option to point to a file called catalog.xml in the project root directory. You can apply the same principles to this file to resolve addresses at compile time.

Some useful links:

Using a JAX-WS Catalog

How to write an XML catalog file

Global URI re-writing with jax-ws-catalog

Enjoy!