Sunday, February 24, 2008

Java: Eclipe's notion of classpath 101

In Eclipse, if you don't specify the build path, your classes by default will be placed in the base classpath of your project module. E.g.
C:\workspaces\myproject\myModuleEJB\classes\xxx

Therefore, your base classpath is C:\workspaces\myproject\myModuleEJB\classes\xxx

Consider two spring config source folders :
C:\workspaces\myproject\myModuleEJB\testsrc\spring\testApplicationContext.xml
C:\workspaces\myproject\myModuleEJB\configsrc\spring\businessRules.xml

testApplicationContext.xml is referring to businessRules.xml e.g.

testApplicationContext.xml
===================

<bean id="businessRules" init="false" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list><value>spring/businessRules.xml</value></list>
</constructor-arg>
</bean>


both testApplicationContext.xml and businessRules.xml are compiled by Eclipse into
C:\workspaces\myproject\myModuleEJB\classes\spring\testApplicationContext.xml
C:\workspaces\myproject\myModuleEJB\classes\spring\businessRules.xml

therefore, if testApplicationContext.xml wants to refer to businessRules.xml, the testApplicationContext.xml has to refer to the base classpath location of businessRules.xml
ie. /spring/businessRules.xml

java: Spring's Hibernate Template now obsolete as of Hibernate 3.0.1

See
http://blog.springsource.com/main/2007/06/26/so-should-you-still-use-springs-hibernatetemplate-andor-jpatemplate/

Also, see
- Spring in Action (2nd ed) page 193

- Beginning Spring 2 page 70

Wednesday, February 13, 2008

java: How to deploy EJB in WebSphere using Ant


<property name="package.lib.dir" value="${lib.dir}/package" />

<target name="create-was-ejb">
<property name="ejbdeploy.classpath.prop" refid="ejbdeploy.classpath" />

<path id="ejbdeploy.classpath">
<fileset dir="${package.lib.dir}" includes="*.jar" />
<pathelement location="${was.home}/java/jre/lib/ibmorb.jar" />
</path>

<taskdef
name="wsejbdeploy"
classname="com.ibm.websphere.ant.tasks.WsEjbDeploy"
classpath="${was.home}/lib/wsanttasks.jar" />

<wsejbdeploy
inputJar="${build.dir}/${ant.project.name}-${version}-tmp.jar"
wasHome="${was.home}"
workingDirectory="${build.dir}/ejb-tmp"
classpath="${ejbdeploy.classpath.prop}"
outputJar="${build.dir}/${ant.project.name}-${version}.jar"
compatible35="false"
keepGenerated="true"
quiet="true"
failonerror="true" />
</target>

Monday, February 04, 2008

linux: Linux directory structure

Below is a typical linux directory structure of interest to me :

/etc - contains the configuration files for the system. /etc/rc.d contains the scripts that get the system started.

/bin - has the essential programs that the system requires to operate.

/usr/bin - contains applications for the system's users.

/sbin, /usr/sbin - contain programs for system administration, mostly for use by the superuser.

/usr/local - used for the installation of software and other files for use on the local machine. What this really means is that software that is not part of the official distribution. When you find interesting programs to install on your system, they should be installed in one of the /usr/local directories. Most often, the directory of choice is /usr/local/bin.

/tmp - is a directory in which programs can write their temporary files.



Source: http://www.linuxcommand.org/lts0040.php

Sunday, February 03, 2008

java: A simple ANT template


<?xml version="1.0" ?>
<project name="secondbuildJAR" default="compile">

<property file="${user.home}/build.properties"/>

<property name="source.dir" location="src"/>
<property name="build.dir" location="build"/>
<property name="build.classes.dir" location="${build.dir}/classes"/>
<property name="distribution.dir" location="dist"/>
<property name="distribution.doc.dir" location="${distribution.dir}/doc" />


<property name="project.name" value="${ant.project.name}" />
<property name="project.version" value="0.1.alpha" />
<property name="target.name" value="${project.name}-${project.version}.jar" />
<property name="target.jar" location="${distribution.dir}/${target.name}" />


<patternset id="meta.files">
<include name="**/*.xml"/>
<include name="**/*.properties"/>
</patternset>


<path id="compile.classpath">
<fileset dir="lib">
<include name="*.jar"/>
<include name="*.zip"/>
</fileset>
</path>



<path id="run.classpath">
<path refid="compile.classpath"/>
<pathelement location="${target.jar}"/>
</path>



<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${distribution.dir}" /> <!--this will delete both dist and dist/doc -->

<mkdir dir="${build.classes.dir}" />
<mkdir dir="${distribution.doc.dir}" />
</target>



<!-- Copy metadata to build classpath -->
<target name="copymetafiles" depends="clean">
<copy todir="${build.classes.dir}">
<fileset dir="${source.dir}">
<patternset refid="meta.files"/>
</fileset>
</copy>
</target>



<target name="compile" depends="copymetafiles" description="Compiles the project">
<javac srcdir="${source.dir}"
destdir="${build.classes.dir}"
debug="${build.debug}">
<classpath refid="compile.classpath"/>
</javac>
</target>


<target name="archive" depends="compile" description="JARs up the project">
<jar destfile="${target.jar}"
duplicate="preserve"
manifest="${source.dir}/META-INF/MANIFEST.MF">
<fileset dir="${build.classes.dir}"/>
</jar>
</target>



<target name="execute" depends="archive" description="Executes the main class">
<echo>running this program now!!!</echo>
<java classname="org.antbook.welcome.Main" classpathref="run.classpath" failonerror="true">
<arg value="a" />
<arg value="b" />
<arg file="." />
</java>
<echo>end running the program!!!</echo>
</target>


<target name="echo">
<echo message="ant.file = ${ant.file}" /><!--where this ant file is located-->
<echo message="ant.home = ${ant.home}" />
<echo>ant.version = ${ant.version}</echo>
<echo>java.home = ${java.home}</echo>
<echo message="ant.java.version = ${ant.java.version}" />
<echo>ant.project.name = ${ant.project.name}</echo>
<echo>user.name = ${user.name}</echo>
<echo>user.home = ${user.home}</echo>
<echo>basedir = ${basedir}</echo>
<echo>build.debug = ${build.debug}</echo>
</target>



</project>