Project

General

Profile

Actions

CdmLibraryDevelopersGuide » History » Revision 1

Revision 1/30 | Next »
Andreas Müller, 12/15/2008 07:20 PM


CDM Library Usage

Maven repository

To integrate the cdmlibray into your personal Maven project pelase add our Maven repository to your POM: http://wp5.e-taxonomy.eu/cdmlib/mavenrepo/

To use the cdm service package add the following dependency to you POM (adapt the right version number !!)

     <dependency>
        <groupId>eu.etaxonomy</groupId>
        <artifactId>cdmlib-service</artifactId>
        <version>1.X</version>
    </dependency>

To create a project site use mvn site:site. Due to the number of depencies you will have to increase the available memory by setting the MAVEN_OPTS parameter to

   SET MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=512m

In order to install a file (e.g. a JAR) in you local repositry:

mvn install:install-file
      -DgroupId=<group-id>
      -DartifactId=<artifact-id>
      -Dversion=<version>
      -Dfile=<path-to-file>
      -Dpackaging=<packaging> (i.e. jar)
      -DgeneratePom=true

e.g. To install aspectjrt version 1.6.2 in your local repositry:

mvn install:install-file  -DgroupId=aspectj -DartifactId=aspectjrt -Dversion=1.6.2 -Dfile=aspectjrt.jar -Dpackaging=jar -DgeneratePom=true

Example: Prepare aspectjrt version 1.6.2 for a remote repository. With this command you in fact create the artifact in local temporary repository and then copy the resulting files to the remote repository:

mvn deploy:deploy-file -DgroupId=aspectj -DartifactId=aspectjrt -Dversion=1.6.2 -Dpackaging=jar -Dfile=aspectjrt.jar -Durl=file:///D:/tmp/repo -DrepositoryId

Also see: How do I install a file in my local repository along with a generic POM

Eclipse setup

To use the entire cdmlibrary with Eclipse, you need some plugins and to follow this installation guide:

    • install maven 2.0.x commandline tools locally (http://maven.apache.org/download.html). Follow the instruction to install maven on your local machine.
    • install subclipse 1.4.x in eclipse if not yet installed (Update Site: http://subclipse.tigris.org/update_1.4.x).
    • make sure Java JDK >= 1.5 is installed (JRE is not enough) and JAVA_HOME is set to JDK path
    • checkout cdmlib and create eclipse artifacts (using e.g. tortoiseSVN):

$ svn co dev.e-taxonomy.eu/svn/trunk/cdmlib/

  • make sure maven has run at least one time (to create the .m2 folder). If unsure how to do this, run mvn install in the new checked out folder ../cdmlib/cmlib-commons

  • Set in Eclipse preferences (not project properties) M2_REPO java class variable (menue: java-buildPath-Classpath), pointing to your local repository.

    • In OSX for example /Users/USERNAME/.m2/repository
    • In WinXP for example C:\Documents and Settings\USERNAME.m2\repository
  • setup new eclipse workspace (where ever you want but using the cdmlib folder may be comfortable

  • create new Java project within the new workspace. Check "Create project from existing source" in the dialog. Choose ../cdmlib/cdmlib-commons as the source directory. Use project name "cdmlib-commons".

  • repeat the last step at least for all projects starting with "cdmlib-"

  • Install AspectJ Development Tools (AJDT) - Plugin (for eclipse) (Update-Site:http://download.eclipse.org/tools/ajdt/33/dev/update)

  • run

$ mvn install

$ mvn eclipse:eclipse

in the cdmlib directory

  • Referesh cdmlib-model project within eclipse

  • Convert the cdmlib-model to AspectJ (right mouse click on project -> AspectJ Tools -> ...).

  • It wasn't clear to me (PC) from the above that at some point, the following must be executed in the "cdmlib" directory. I did this after all the above steps were completed, and the build was successful.

$ mvn install

$ mvn eclipse:eclipse

Spring applications with cdmlib

In your own applicationContext.xml you can simply import the cdm service spring beans from the library. In addition it also needs a datasource bean and a hibernateProperties bean specific for that datasource. The CDM Library comes with an embedded hypersonic database that is super easy to use. All you need to do is to import that hsql specific spring configuration like this:

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <import resource="classpath:/eu/etaxonomy/cdm/services.xml" />
    <import resource="classpath:/eu/etaxonomy/cdm/hsql-datasource.xml" />

</beans>

In case you want to define the datasource within your own applicationContext you can surely do so. For a typical mysql database it looks like this:

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <import resource="classpath:/eu/etaxonomy/cdm/services.xml" />

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://192.168.2.10/cdm_build"/>
        <property name="username" value="cdm_user"/>
        <property name="password" value="why_do_i_need_this"/>
    </bean>

    <bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="properties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">validate</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.format_sql">false</prop>
            </props>
        </property>
    </bean>    
</beans>

Background

Hibernate

Spring 2.0 Framework

We use the Spring 2.0 framework to develop the library and keep the coupling of components low.

Domain Models

Property Change

Useful Patterns

Aspect Oriented Programming

We use AspectJ to implement the change property crosscutting concern:

Updated by Andreas Müller over 15 years ago · 1 revisions