dcm4che2 Fedora Installation Tips

Installation tip for RedHat/Fedora

Java installation (optional)

This step is optional - take it as an inspiration and only dig into it, if you find installation and maintanance of java goodies a pain.

Java and java libraries are best installed with JPackage. JPackage provides most of java goodies in form of RPMs (some as nosrc.RPMs only) thet you can install to "coorect" locations using JPackage yum repository as well as a set of tools to help you with maintanance of Java. The learning curve of JPackage is a little steep, but I think it's worth it, especially if you're in danger of installing new machines frequently. It's a significant step in keeping java things tidy on your computer.

I won't describe the installation here - refer to the JPackage site for info.

Below installation of Maven and Dcm4che2 are both compliant with JPackage - if it's installed, however they are benefitial even of you don't use JPackage. 

Maven installation patch (developers only)

If you want to work with the sources, you'll have to go the maven way - and thus install maven.. If you downloaded the binary version, just skip this. 

Maven does not conform to "good RH practices". With the standard installation you end up with MAVEN_HOME environment variable and an entry in you PATH that enables you to access the mvn launch script from anywhere. Furthermore the mvn script is hardcoded to use the JAVA_HOME env. variable to locate your JRE.

Here is what you should do:

  • Install maven to /opt/maven-$VERSION or anywhere it fits you
  • in /usr/local create symlink to maven installdir called maven
  • in /usr/local/bin create a link to maven start script
  • patch the start script with the patch provided here
> log in as root > cd /usr/bin> ln -s /opt/maven-2.0.2 maven> cd bin> ln -s ../maven/bin/mvn
  • the patch:
--- /usr/local/maven/bin/mvn.orig	2006-03-03 13:09:27.000000000 -0700
+++ /usr/local/maven/bin/mvn	2006-03-03 13:49:39.000000000 -0700
@@ -44,7 +44,11 @@
 esac

 if [ -z "$JAVA_HOME" ] ; then
-  if [ -e /etc/gentoo-release ] ; then
+  # Use jpackage.org java setup if available
+  if [ -e /usr/share/java-utils/java-functions ] ; then
+    . /usr/share/java-utils/java-functions
+    set_javacmd
+  elif [ -e /etc/gentoo-release ] ; then
     JAVA_HOME=`java-config --jre-home`
   fi
 fi
@@ -53,6 +57,8 @@
   # try to find MAVEN
   if [ -d /opt/m2 ] ; then
     MAVEN_HOME=/opt/m2
+  elif [ -d /usr/local/maven ] ; then
+    MAVEN_HOME=/usr/local/maven
   fi

   if [ -d "$HOME/m2" ] ; then
  • and you're ready to run maven from everywhere, upgrade to new version.. - without any environment variables, path etc.
Dcm4che2 isntallation patch

Is very similar to what we've done with maven.

  • Install it wherever you want (/opt/dcm4che-$VERSION)
  • create link to the installdir in your /usr/local called dcm4che2
  • create links to start scripts (located in /usr/local/dcm4che2/bin) to utilities you'd like to use in /usr/local/bin
  • unfortunately you'll have to patch the start scripts of the utilities manually - I provide example fot dcm2xml here
> log in as root > cd /usr/bin> ln -s /opt/dcm4che-2.0.6 dcm4che2> cd /bin> ln -s ../dcm4che2/bin/dcm2xml> ...
  • dcm2xml start script (replacing dcm4che2/bin/dcm2xml):
  • all the start scripts are nearly identical, differing only in MAIN_CLASS and MAIN_JAR variables, so you can easily use this for all of them
#!/bin/sh
### ====================================================================== ###
##                                                                          ##
##  dcm4che2/dcm2xml  Launch Script                                         ##
##                                                                          ##
### ====================================================================== ###

### $Id: dcm2xml,v 1.22 2006/06/16 12:14:13 gunterze Exp $ ###

MAIN_CLASS=org.dcm4che2.tool.dcm2xml.Dcm2Xml
MAIN_JAR=dcm4che-tool-dcm2xml-2.0.6.jar

DIRNAME=`dirname $0`

# OS specific support (must be 'true' or 'false').
cygwin=false;
case "`uname`" in
    CYGWIN*)
        cygwin=true
        ;;
esac

# Setup DCM4CHE2_HOME
#if [ "x$DCM4CHE2_HOME" = "x" ]; then
#    DCM4CHE2_HOME=`cd $DIRNAME/..; pwd`
#fi
if [ -z "$DCM4CHE2_HOME" ] ; then
  # try to find DCM4CHE2
  if [ -d /opt/dcm4che2 ] ; then
    DCM4CHE2_HOME=/opt/dcm4che2
  elif [ -d /usr/local/dcm4che2 ] ; then
    DCM4CHE2_HOME=/usr/local/dcm4che2
  elif [ -d "$HOME/m2" ] ; then
    DCM4CHE2_HOME="$HOME/m2"
  else
    DCM4CHE2_HOME=`cd $DIRNAME/..; pwd`
  fi
fi

# Setup the JVM
#if [ "x$JAVA_HOME" != "x" ]; then
#    JAVA=$JAVA_HOME/bin/java
#else
#    JAVA="java"
#fi
if [ -z "$JAVA_HOME" ] ; then
  # Use jpackage.org java setup if available
  if [ -e /usr/share/java-utils/java-functions ] ; then
    . /usr/share/java-utils/java-functions
    set_javacmd
  elif [ -e /etc/gentoo-release ] ; then
    JAVA_HOME=`java-config --jre-home`
  fi
fi

if [ -z "$JAVACMD" ] ; then
  if [ -n "$JAVA_HOME"  ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
      # IBM's JDK on AIX uses strange locations for the executables
      JAVACMD="$JAVA_HOME/jre/sh/java"
    else
      JAVACMD="$JAVA_HOME/bin/java"
    fi
  else
    JAVACMD=java
  fi
fi

if [ ! -x "$JAVACMD" ] ; then
  echo "Error: JAVA_HOME is not defined correctly."
  echo "  We cannot execute $JAVACMD"
  exit 1
fi

# Setup the classpath
CP="$DCM4CHE2_HOME/etc/"
CP="$CP:$DCM4CHE2_HOME/lib/$MAIN_JAR"
CP="$CP:$DCM4CHE2_HOME/lib/dcm4che-core-2.0.6.jar"
CP="$CP:$DCM4CHE2_HOME/lib/nlog4j-1.2.19.jar"
CP="$CP:$DCM4CHE2_HOME/lib/commons-cli-1.0.jar"

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
    [ -n "$DCM4CHE2_HOME" ] &&
        DCM4CHE2_HOME=`cygpath --unix "$DCM4CHE2_HOME"`
    [ -n "$JAVA_HOME" ] &&
        JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
    [ -n "$JAVACMD" ] &&
        JAVACMD=`cygpath --unix "$JAVACMD"`
    [ -n "$CP" ] &&
        CP=`cygpath --path --unix "$CP"`
fi

# Execute the JVM
exec $JAVACMD $JAVA_OPTS -cp $CP $MAIN_CLASS "$@"

Of course it would be great to have this done automatically in rpm installation, but creating it is for the moment out of scope - for Dcm4che2 and for Maven as well. If you're insterested, you can contribute!