Wednesday, April 26, 2006

How to generate checksum files for Maven 2 repository

Sometimes you want to add libraries to your Maven 2 repository manually.
This tool will help you to generate checksum files recursively, starting from current directory.

Tool is located here.

You can use Scriptlangia in order to simplify launching of this tool.

Tuesday, April 25, 2006

Beanshell plugin for maven2

Plugin for running beanshell scripts in the same way as maven-antrun-plugin does. Based on the source from maven-antrun-plugin plugin.

Source code is located here: maven-beanshell-plugin.

in order to use the plugin you have to add new repository to the list of your repositories:


Then, configure the plugin:


            <!--content>print("Hello, World!");</content-->

New maven2 book (free, pre-release): Better Builds with Maven

Saturday, April 22, 2006

Scriptlandia Project Home Page

Welcome to the Scriptlandia World!

I started this project two years ago (Antlets). The idea was to simplify running various scripts written in scripting languages (Beanshell, Groovy, Jelly etc.) for JVM under Windows and Unix environment.

We have a plenty of scripting engines, each has the launcher/starter program. In order to run the script, you have to remember the name of the launcher program. In case if you need to add new libraries to your script, it's not so easy. If you want to have scripts in different languages to be aware of each other, it's even more difficult.

Scriptlandia is built in top of ClassWorlds framework, a convenient way of solving classloader problems in one unified way. Your batch/shell scripts will become as simple as possible and addition of new libraries will happen outside of them.

By the size this project is very small (~70K). It uses Maven2 as the delivery mechanizm to download all required parts. It has to deliver libraries for running Beanshell, Groovy etc. from Maven2 repositories.

After installing the Scriptlandia you will be able to launch beanshell, groovy, jelly, velocity scripts in one click. You can do the same for jar files. If jar file is written for Java Micro Edition, the system will recognize it and the file will be started in mobile phone emulator. See examples archive for more details. This file: README.txt contains complete description of the project.

Princeton JUG site

Tuesday, April 04, 2006

How to pre-compile JSP pages for Tomcat with Ant

JSP pre-compilation is very important part of the build process. Even if you don't want to use pre-compiled pages in your production environment (it's for specific application server (AS) only), it can guarantee the integrity of your source.

With regular approach you make changes to JSP pages, then copy/deploy them to AS and only at this time possible error will be discovered. In contrast, JSP pre-compilation will give you this knowledge at compile time.

How to do the pre-compilation? I will explain it with the help of Ant build tool.

1. Specify "project.classpath" for your project. It will include all jars required to compile or run your project:

<path id="project.classpath">

2. Specify "tomcat.jsp.classpath". You need to have Tomcat Web Server installed somewhere. For this example I use tomcat, embedded into JBoss Application Server ("${jboss.home}").

You also need to specify where you have your implementation of logging system

<path id="tomcat.jsp.classpath">

<!-- 1. You have to include jars from your project. -->

<path refid="project.classpath"/>

<!-- 2. Tomcat jsp compiler (jasper) by itself. -->

<fileset dir="${jboss.home}/server/default/deploy/jbossweb-tomcat55.sar">
<include name ="jasper-compiler.jar"/>
<include name ="jasper-compiler-jdt.jar"/>
<include name ="jasper-runtime.jar"/>
<include name ="commons-logging.jar"/>
<include name ="commons-el.jar"/>
<include name ="jsp-api.jar"/>

<!-- 3. This library is required by jasper. -->

<fileset dir="${ant.home}/lib">
<include name ="ant.jar"/>

<!-- 4. JavaEE/Servlet/JSP interface classes. -->

<fileset dir="${jboss.home}/server/default/lib">
<include name ="jboss-j2ee.jar"/>
<include name ="javax.servlet.jar"/>
<include name ="javax.servlet.jsp.jar"/>

<!-- 5. Implementation of logging system (if it is not in "project.classpath" yet). -->

<fileset dir="${repository.home}/log4j">
<include name ="log4j-1.2.8.jar"/>


3. Now we can generate Java sources for JSP files:

<property name="jsp.src.dir" value="<the root for your JSP files>"/>
<property name="" value="<the package name for your JSPs, like com.mycompany.jsp>"/>

<property name="build.dir" value="target/build"/>
<property name="jsp.generated.src.dir" value="${build.dir}/jsp_sources"/>
<property name="jsp.classes.dir" value="${build.dir}/jsp_classes"/>

<target name="tomcat.jsp.generate">
<mkdir dir="${jsp.generated.src.dir}"/>
<mkdir dir="${jsp.classes.dir}"/>

<java classname="org.apache.jasper.JspC" fork="yes">
<classpath refid="tomcat.jsp.classpath" />

<arg line="-uriroot ${jsp.src.dir} -d ${jsp.generated.src.dir} -p ${} -webapp ${jsp.src.dir}" />

4. After the generation of Java classes from JSPs, we need to compile them. The "depend" task is responsible for "smart" recompilation of JSP-Java files.

<target name="tomcat.jsp.compile" depends="tomcat.jsp.generate"
description="Generates java classes from jsp files, then compiles them">
<depend srcdir="${jsp.src.dir}"
<classpath refid="tomcat.jsp.classpath"/>

<javac destdir="${jsp.classes.dir}" debug="off" optimize="false">
<classpath refid="tomcat.jsp.classpath"/>

<src path="${jsp.generated.src.dir}"/>
<include name ="com/**/*.java"/>

If on this step you don't have compiler errors, your source code (JSP part) is not broken.