Thursday, 6 September 2007

Easy syntax highlight embedded code on your blog

For some time I have been looking for a easy way to syntax highlight code snippets on my blog as my default stylesheet seems to do a bad job.

I came across tools like:

But the one I found most interesting is google-code-prettify that Hung Huynh recommended me.

Prettify only requires you to include a small stylesheet and a single javascript file containing the code doing the hard work - see the simple readme
Then you just surround you code with - say <pre class="prettyprint"> and voila! your code is syntax highlighted.

I have updated some of my older posts so you can see the prettifier in action:

Tuesday, 4 September 2007

Maven defaults is missing something

Mavens defined conventions for resources as follows:

  • Java files in src/main/java
  • All resources in src/main/resources
And on the surface it seems fine. Keep your java source and resources separated and clean.
But for some resources it makes sence to keep them "close" to the java class using it - say in the same package. I could do that by duplicating package structure in my resources directory, but that would be repeating myself and breaking the good old DRY principle. But furthermore and much more important I risk to miss the resource files when refactoring my build (renaming packages, moving classes).

So I always end up overwriting the resources definition in my pom.xml to something like this:
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${basedir}/src/main/java</directory>
</resource>
</resources>
</build>
I have been one of the defenders of mavens conventions, but this time it seems to be missing something.
Can anyone tell me why this isn't the default in maven?
I can't be the only one placing resources along side with my java files.