From bbadcb75d4629441e73ea04782ae2c5decf64fe3 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 17 Dec 2007 10:43:53 +0000
Subject: [PATCH] 2730: New - The setup command should perform some basic memory tuning Note: this issue is not fully covered by the proposed modifications but all that is missing in order to fix it is to figure out which are the default memory values that we want to propose in the setup.

---
 opends/resource/bin/encode-password                                             |    4 
 opends/resource/bin/stop-ds.bat                                                 |   51 
 opends/resource/bin/dsreplication                                               |    4 
 opends/resource/bin/status-panel                                                |    4 
 opends/resource/bin/_mixed-script.sh                                            |  105 +
 opends/resource/bin/dsreplication.bat                                           |    2 
 opends/resource/bin/restore.bat                                                 |    4 
 opends/resource/bin/make-ldif.bat                                               |    2 
 opends/resource/bin/ldapmodify                                                  |    4 
 opends/resource/bin/backup.bat                                                  |    4 
 opends/resource/bin/create-rc-script                                            |    4 
 opends/resource/bin/export-ldif                                                 |    6 
 opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java      |  292 ++++
 opends/resource/bin/manage-account.bat                                          |    2 
 opends/resource/bin/dsconfig.bat                                                |    2 
 opends/resource/bin/ldappasswordmodify                                          |    4 
 opends/resource/bin/ldapcompare                                                 |    4 
 opends/resource/bin/backup                                                      |    6 
 opends/resource/bin/_script-util.bat                                            |  170 ++
 opends/resource/bin/start-ds.bat                                                |   62 
 opends/resource/bin/dsconfig                                                    |    4 
 opends/resource/bin/manage-account                                              |    4 
 opends/src/server/org/opends/server/tools/InstallDS.java                        |   39 
 opends/resource/bin/ldifmodify                                                  |    4 
 opends/resource/bin/stop-ds                                                     |   96 -
 opends/resource/bin/ldifsearch                                                  |    4 
 opends/resource/bin/_script-util.sh                                             |  177 ++
 opends/resource/bin/encode-password.bat                                         |    2 
 opends/resource/bin/dbtest.bat                                                  |    2 
 opends/src/quicksetup/org/opends/quicksetup/Installation.java                   |   27 
 opends/resource/bin/ldapcompare.bat                                             |    2 
 opends/resource/bin/dbtest                                                      |    4 
 opends/resource/setup.bat                                                       |   62 
 opends/src/server/org/opends/server/tools/JavaPropertiesToolArgumentParser.java |  194 +++
 opends/resource/bin/ldapdelete                                                  |    4 
 opends/resource/upgrade                                                         |  104 -
 opends/resource/bin/ldif-diff                                                   |    4 
 opends/resource/bin/manage-tasks                                                |    4 
 opends/resource/uninstall.bat                                                   |   59 
 opends/resource/bin/start-ds                                                    |  100 -
 opends/resource/bin/verify-index                                                |    4 
 opends/resource/bin/base64.bat                                                  |    2 
 opends/resource/bin/restore                                                     |    6 
 opends/resource/bin/_server-script.bat                                          |   47 
 opends/resource/bin/ldapsearch                                                  |    4 
 opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java  |   23 
 opends/resource/bin/list-backends.bat                                           |    2 
 opends/resource/bin/status-panel.bat                                            |   48 
 opends/resource/bin/_client-script.sh                                           |   68 
 opends/resource/uninstall                                                       |   97 -
 opends/resource/bin/_mixed-script.bat                                           |   76 +
 opends/resource/bin/_client-script.bat                                          |   47 
 opends/resource/bin/dsframework                                                 |    4 
 opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java            |    3 
 opends/src/server/org/opends/server/tools/JavaPropertiesTool.java               | 1004 ++++++++++++++++
 opends/resource/bin/status.bat                                                  |    2 
 opends/resource/bin/ldifmodify.bat                                              |    2 
 opends/resource/bin/make-ldif                                                   |    4 
 opends/resource/bin/manage-tasks.bat                                            |    2 
 opends/resource/bin/ldapmodify.bat                                              |    2 
 opends/resource/bin/ldif-diff.bat                                               |    2 
 opends/resource/bin/dsjavaproperties.bat                                        |   32 
 opends/resource/bin/list-backends                                               |    4 
 opends/resource/bin/status                                                      |    4 
 opends/resource/upgrade.bat                                                     |   55 
 opends/resource/bin/dsframework.bat                                             |    2 
 opends/resource/bin/windows-service.bat                                         |    2 
 opends/resource/bin/export-ldif.bat                                             |    4 
 opends/resource/bin/ldifsearch.bat                                              |    2 
 opends/resource/bin/_server-script.sh                                           |   68 
 opends/resource/bin/ldappasswordmodify.bat                                      |    2 
 opends/src/messages/messages/quicksetup.properties                              |    2 
 opends/src/messages/messages/tools.properties                                   |   28 
 opends/src/server/org/opends/server/util/SetupUtils.java                        |  144 --
 opends/resource/bin/import-ldif                                                 |    6 
 opends/resource/bin/dsjavaproperties                                            |   37 
 opends/build.xml                                                                |   14 
 opends/resource/bin/rebuild-index.bat                                           |    2 
 opends/resource/bin/verify-index.bat                                            |    2 
 opends/resource/bin/ldapdelete.bat                                              |    2 
 opends/resource/bin/base64                                                      |    4 
 opends/src/server/org/opends/server/tools/tasks/TaskTool.java                   |   44 
 opends/resource/bin/import-ldif.bat                                             |    4 
 opends/resource/bin/rebuild-index                                               |    4 
 opends/resource/bin/ldapsearch.bat                                              |    2 
 opends/resource/setup                                                           |   98 -
 86 files changed, 2,463 insertions(+), 1,186 deletions(-)

diff --git a/opends/build.xml b/opends/build.xml
index 20f4d79..5fad80c 100644
--- a/opends/build.xml
+++ b/opends/build.xml
@@ -831,11 +831,11 @@
 
     <antcall target="example-plugin" />
 
-    <fixcrlf srcDir="${scripts.dir}" destDir="${pdir}/bin" excludes="*.bat,_client-script.sh,_server-script.sh" eol="lf" />
-    <fixcrlf srcDir="${scripts.dir}" destDir="${pdir}/lib" includes="_client-script.sh,_server-script.sh" eol="lf" />
+    <fixcrlf srcDir="${scripts.dir}" destDir="${pdir}/bin" excludes="*.bat,_client-script.sh,_server-script.sh,_mixed-script.sh,_script-util.sh" eol="lf" />
+    <fixcrlf srcDir="${scripts.dir}" destDir="${pdir}/lib" includes="_client-script.sh,_server-script.sh,_mixed-script.sh,_script-util.sh" eol="lf" />
     <fixcrlf srcDir="${scripts.dir}" destDir="${pdir}/bin" includes="README_WINDOWS.txt" eol="crlf" />
-    <fixcrlf srcDir="${scripts.dir}" destDir="${pdir}/bat" excludes="_client-script.bat,_server-script.bat,setcp.bat" includes="*.bat" eol="crlf" />
-    <fixcrlf srcDir="${scripts.dir}" destDir="${pdir}/lib" includes="_client-script.bat,_server-script.bat,setcp.bat" eol="crlf" />
+    <fixcrlf srcDir="${scripts.dir}" destDir="${pdir}/bat" excludes="_client-script.bat,_server-script.bat,_mixed-script.bat,_script-util.bat,setcp.bat" includes="*.bat" eol="crlf" />
+    <fixcrlf srcDir="${scripts.dir}" destDir="${pdir}/lib" includes="_client-script.bat,_server-script.bat,_mixed-script.bat,_script-util.bat,setcp.bat" eol="crlf" />
 
     <copy todir="${pdir}/config">
       <fileset file="${config.dir}/*" />
@@ -924,6 +924,8 @@
     </chmod>
     <chmod file="${pdir}/lib/_client-script.sh" perm="755" />
     <chmod file="${pdir}/lib/_server-script.sh" perm="755" />
+    <chmod file="${pdir}/lib/_mixed-script.sh" perm="755" />
+    <chmod file="${pdir}/lib/_script-util.sh" perm="755" />
   </target>
 
 
@@ -934,10 +936,10 @@
        description="Package the Directory Server for distribution.">
     <zip destfile="${package.dir}/${SHORT_NAME}-${VERSION_NUMBER_STRING}.zip">
       <zipfileset dir="${package.dir}" includes="${SHORT_NAME}-${VERSION_NUMBER_STRING}/**/*"
-           excludes="${SHORT_NAME}-${VERSION_NUMBER_STRING}/bin/*,${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_client-script.sh,${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_server-script.sh,${SHORT_NAME}-${VERSION_NUMBER_STRING}/setup,${SHORT_NAME}-${VERSION_NUMBER_STRING}/uninstall,${SHORT_NAME}-${VERSION_NUMBER_STRING}/upgrade,${SHORT_NAME}-${VERSION_NUMBER_STRING}/QuickSetup.app/Contents/MacOS/JavaApplicationStub,${SHORT_NAME}-${VERSION_NUMBER_STRING}/Uninstall.app/Contents/MacOS/JavaApplicationStub,${SHORT_NAME}-${VERSION_NUMBER_STRING}/bin/StatusPanel.app/Contents/MacOS/JavaApplicationStub"
+           excludes="${SHORT_NAME}-${VERSION_NUMBER_STRING}/bin/*,${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_client-script.sh,${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_script-util.sh,${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_server-script.sh,${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_mixed-script.sh,${SHORT_NAME}-${VERSION_NUMBER_STRING}/setup,${SHORT_NAME}-${VERSION_NUMBER_STRING}/uninstall,${SHORT_NAME}-${VERSION_NUMBER_STRING}/upgrade,${SHORT_NAME}-${VERSION_NUMBER_STRING}/QuickSetup.app/Contents/MacOS/JavaApplicationStub,${SHORT_NAME}-${VERSION_NUMBER_STRING}/Uninstall.app/Contents/MacOS/JavaApplicationStub,${SHORT_NAME}-${VERSION_NUMBER_STRING}/bin/StatusPanel.app/Contents/MacOS/JavaApplicationStub"
            filemode="644" dirmode="755" />
       <zipfileset dir="${package.dir}"
-           includes="${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_client-script.sh,${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_server-script.sh"
+           includes="${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_client-script.sh,${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_script-util.sh,${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_server-script.sh,${SHORT_NAME}-${VERSION_NUMBER_STRING}/lib/_mixed-script.sh"
            filemode="755" dirmode="755" />
       <zipfileset dir="${package.dir}" includes="${SHORT_NAME}-${VERSION_NUMBER_STRING}/bin/*"
            excludes="${SHORT_NAME}-${VERSION_NUMBER_STRING}/bin/README_WINDOWS.txt"
diff --git a/opends/resource/bin/_client-script.bat b/opends/resource/bin/_client-script.bat
index eb1b413..f1e9011 100644
--- a/opends/resource/bin/_client-script.bat
+++ b/opends/resource/bin/_client-script.bat
@@ -33,54 +33,19 @@
 set INSTANCE_ROOT=%DIR_HOME%
 
 if "%OPENDS_INVOKE_CLASS%" == "" goto noInvokeClass
-goto checkOpenDSJavaBin
+goto launchCommand
 
 :noInvokeClass
 echo Error:  OPENDS_INVOKE_CLASS environment variable is not set.
 pause
 goto end
 
-:checkOpenDSJavaBin
-if "%OPENDS_JAVA_BIN%" == "" goto checkOpenDSJavaHome
-goto setClassPath
+:launchCommand
+set SCRIPT_UTIL_CMD=set-full-environment
+call "%INSTANCE_ROOT%\lib\_script-util.bat"
+if NOT %errorlevel% == 0 exit /B %errorlevel%
 
-:checkOpenDSJavaHome
-if "%OPENDS_JAVA_HOME%" == "" goto checkOpenDSJavaHomeFile
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkOpenDSJavaHomeFile
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkOpenDSJavaHomeFile
-if not exist "%DIR_HOME%\lib\set-java-home.bat" goto checkJavaBin
-call "%DIR_HOME%\lib\set-java-home.bat"
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkJavaBin
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkJavaBin
-if "%JAVA_BIN%" == "" goto checkJavaHome
-set OPENDS_JAVA_BIN=%JAVA_BIN%
-goto setClassPath
-
-:checkJavaHome
-if "%JAVA_HOME%" == "" goto noJavaHome
-if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
-set OPENDS_JAVA_BIN=%JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:noJavaHome
-echo Error: OPENDS_JAVA_HOME environment variable is not set.
-echo        Please set it to a valid Java 5 (or later) installation.
-pause
-goto end
-
-:setClassPath
-FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\lib\setcp.bat" %%x
-
-set PATH=%SystemRoot%
-
-"%OPENDS_JAVA_BIN%" %JAVA_ARGS% %SCRIPT_NAME_ARG% %OPENDS_INVOKE_CLASS% %*
-
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG% %OPENDS_INVOKE_CLASS% %*
 
 :end
 
diff --git a/opends/resource/bin/_client-script.sh b/opends/resource/bin/_client-script.sh
index 7ac2885..cb5d760 100755
--- a/opends/resource/bin/_client-script.sh
+++ b/opends/resource/bin/_client-script.sh
@@ -50,65 +50,15 @@
 cd "${WORKING_DIR}"
 
 
-# See if the environment variables are set.  If not, then see if there is a java
-# executable in the path and try to figure it out.
-if test -z "${OPENDS_JAVA_BIN}"
+# Set environment variables
+SCRIPT_UTIL_CMD=set-full-environment
+export SCRIPT_UTIL_CMD
+.  "${INSTANCE_ROOT}/lib/_script-util.sh"
+RETURN_CODE=$?
+if test ${RETURN_CODE} -ne 0
 then
-  if test -z "${OPENDS_JAVA_HOME}"
-  then
-    if test -f "${INSTANCE_ROOT}/lib/set-java-home"
-    then
-      . "${INSTANCE_ROOT}/lib/set-java-home"
-      OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-      export OPENDS_JAVA_BIN
-    else
-      if test -z "${JAVA_BIN}"
-      then
-        if test -z "${JAVA_HOME}"
-        then
-          OPENDS_JAVA_BIN=`which java 2> /dev/null`
-          if test ${?} -eq 0
-          then
-            export OPENDS_JAVA_BIN
-          else
-            echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-            exit 1
-          fi
-        else
-          OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
-          export OPENDS_JAVA_BIN
-        fi
-      else
-        OPENDS_JAVA_BIN="${JAVA_BIN}"
-        export OPENDS_JAVA_BIN
-      fi
-    fi
-  else
-    OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-    export OPENDS_JAVA_BIN
-  fi
+  exit ${RETURN_CODE}
 fi
 
-# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
-# system environment variables for security and compatibility reasons.
-PATH=/bin:/usr/bin
-LD_LIBRARY_PATH=
-LD_LIBRARY_PATH_32=
-LD_LIBRARY_PATH_64=
-LD_PRELOAD=
-LD_PRELOAD_32=
-LD_PRELOAD_64=
-export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
-       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
-
-
-# Configure the appropriate CLASSPATH.
-CLASSPATH=${INSTANCE_ROOT}/classes
-for JAR in ${INSTANCE_ROOT}/lib/*.jar
-do
-  CLASSPATH=${CLASSPATH}:${JAR}
-done
-export CLASSPATH
-
-# Launch the appropriate server utility.
-"${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} "${OPENDS_INVOKE_CLASS}" "${@}"
+# Launch the appropriate client utility.
+"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} "${OPENDS_INVOKE_CLASS}" "${@}"
diff --git a/opends/resource/bin/_mixed-script.bat b/opends/resource/bin/_mixed-script.bat
new file mode 100644
index 0000000..f250034
--- /dev/null
+++ b/opends/resource/bin/_mixed-script.bat
@@ -0,0 +1,76 @@
+
+@echo off
+rem CDDL HEADER START
+rem
+rem The contents of this file are subject to the terms of the
+rem Common Development and Distribution License, Version 1.0 only
+rem (the "License").  You may not use this file except in compliance
+rem with the License.
+rem
+rem You can obtain a copy of the license at
+rem trunk/opends/resource/legal-notices/OpenDS.LICENSE
+rem or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+rem See the License for the specific language governing permissions
+rem and limitations under the License.
+rem
+rem When distributing Covered Code, include this CDDL HEADER in each
+rem file and include the License file at
+rem trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+rem add the following below this CDDL HEADER, with the fields enclosed
+rem by brackets "[]" replaced with your own identifying information:
+rem      Portions Copyright [yyyy] [name of copyright owner]
+rem
+rem CDDL HEADER END
+rem
+rem
+rem      Portions Copyright 2006-2007 Sun Microsystems, Inc.
+
+rem This script is used to invoke various server-side processes.  It should not
+rem be invoked directly by end users.
+
+setlocal
+for %%i in (%~sf0) do set DIR_HOME=%%~dPsi..
+set INSTANCE_ROOT=%DIR_HOME%
+
+if "%OPENDS_INVOKE_CLASS%" == "" goto noInvokeClass
+
+set OLD_SCRIPT_NAME=%SCRIPT_NAME%
+set SCRIPT_NAME=%OLD_SCRIPT_NAME%.online
+
+set SCRIPT_UTIL_CMD=set-full-environment
+call "%INSTANCE_ROOT%\lib\_script-util.bat"
+if NOT %errorlevel% == 0 exit /B %errorlevel%
+
+set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=%OLD_SCRIPT_NAME%"
+
+rem Check whether is local or remote
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG% %OPENDS_INVOKE_CLASS% --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" --testIfOffline %*  
+if %errorlevel% == 51 goto launchoffline
+if %errorlevel% == 52 goto launchonline
+exit /B %errorlevel%
+
+:noInvokeClass
+echo Error:  OPENDS_INVOKE_CLASS environment variable is not set.
+pause
+goto end
+
+:launchonline
+
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG% %OPENDS_INVOKE_CLASS% --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
+
+goto end
+
+:launchoffline
+set SCRIPT_NAME=%OLD_SCRIPT_NAME%.offline
+
+set SCRIPT_UTIL_CMD=set-full-environment
+call "%INSTANCE_ROOT%\lib\_script-util.bat"
+if NOT %errorlevel% == 0 exit /B %errorlevel%
+set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=%OLD_SCRIPT_NAME%"
+
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG% %OPENDS_INVOKE_CLASS% --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
+
+goto end
+
+:end
+
diff --git a/opends/resource/bin/_mixed-script.sh b/opends/resource/bin/_mixed-script.sh
new file mode 100644
index 0000000..daed6a7
--- /dev/null
+++ b/opends/resource/bin/_mixed-script.sh
@@ -0,0 +1,105 @@
+#!/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License").  You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at
+# trunk/opends/resource/legal-notices/OpenDS.LICENSE
+# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at
+# trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+# add the following below this CDDL HEADER, with the fields enclosed
+# by brackets "[]" replaced with your own identifying information:
+#      Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#      Portions Copyright 2007 Sun Microsystems, Inc.
+
+
+# This script is used to invoke processes that might be run on server or
+# in client mode (depending on the state of the server and the arguments
+# passed).  It should not be invoked directly by end users.
+if test -z "${OPENDS_INVOKE_CLASS}"
+then
+  echo "ERROR:  OPENDS_INVOKE_CLASS environment variable is not set."
+  exit 1
+fi
+
+
+# Capture the current working directory so that we can change to it later.
+# Then capture the location of this script and the Directory Server instance
+# root so that we can use them to create appropriate paths.
+WORKING_DIR=`pwd`
+
+cd `dirname "${0}"`
+SCRIPT_DIR=`pwd`
+
+cd ..
+INSTANCE_ROOT=`pwd`
+export INSTANCE_ROOT
+
+cd "${WORKING_DIR}"
+
+OLD_SCRIPT_NAME=${SCRIPT_NAME}
+SCRIPT_NAME=${OLD_SCRIPT_NAME}.online
+export SCRIPT_NAME
+
+# Set environment variables
+SCRIPT_UTIL_CMD=set-full-environment
+export SCRIPT_UTIL_CMD
+.  "${INSTANCE_ROOT}/lib/_script-util.sh"
+RETURN_CODE=$?
+if test ${RETURN_CODE} -ne 0
+then
+  exit ${RETURN_CODE}
+fi
+
+MUST_CALL_AGAIN="false"
+
+SCRIPT_NAME_ARG=-Dorg.opends.server.scriptName=${OLD_SCRIPT_NAME}
+export SCRIPT_NAME_ARG
+
+# Check whether is local or remote
+"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} "${OPENDS_INVOKE_CLASS}" \
+     --configClass org.opends.server.extensions.ConfigFileHandler \
+     --configFile "${INSTANCE_ROOT}/config/config.ldif" --testIfOffline "${@}"  
+EC=${?}
+if test ${EC} -eq 51
+then
+  # Set the environment to use the offline properties
+  SCRIPT_NAME=${OLD_SCRIPT_NAME}.offline
+  export SCRIPT_NAME
+  .  "${INSTANCE_ROOT}/lib/_script-util.sh"
+  RETURN_CODE=$?
+  if test ${RETURN_CODE} -ne 0
+  then
+    exit ${RETURN_CODE}
+  fi
+  MUST_CALL_AGAIN="true"
+else
+  if test ${EC} -eq 52
+  then
+    MUST_CALL_AGAIN="true"
+  fi
+fi
+
+if test ${MUST_CALL_AGAIN} = "true"
+then
+  SCRIPT_NAME_ARG=-Dorg.opends.server.scriptName=${OLD_SCRIPT_NAME}
+  export SCRIPT_NAME_ARG
+  
+  # Launch the server utility.
+  "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} "${OPENDS_INVOKE_CLASS}" \
+       --configClass org.opends.server.extensions.ConfigFileHandler \
+       --configFile "${INSTANCE_ROOT}/config/config.ldif" "${@}"
+fi
diff --git a/opends/resource/bin/_script-util.bat b/opends/resource/bin/_script-util.bat
new file mode 100644
index 0000000..89da6a2
--- /dev/null
+++ b/opends/resource/bin/_script-util.bat
@@ -0,0 +1,170 @@
+
+@echo off
+rem CDDL HEADER START
+rem
+rem The contents of this file are subject to the terms of the
+rem Common Development and Distribution License, Version 1.0 only
+rem (the "License").  You may not use this file except in compliance
+rem with the License.
+rem
+rem You can obtain a copy of the license at
+rem trunk/opends/resource/legal-notices/OpenDS.LICENSE
+rem or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+rem See the License for the specific language governing permissions
+rem and limitations under the License.
+rem
+rem When distributing Covered Code, include this CDDL HEADER in each
+rem file and include the License file at
+rem trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+rem add the following below this CDDL HEADER, with the fields enclosed
+rem by brackets "[]" replaced with your own identifying information:
+rem      Portions Copyright [yyyy] [name of copyright owner]
+rem
+rem CDDL HEADER END
+rem
+rem
+rem      Portions Copyright 2007 Sun Microsystems, Inc.
+
+set SET_JAVA_HOME_AND_ARGS_DONE=false
+set SET_ENVIRONMENT_VARS_DONE=false
+set SET_CLASSPATH_DONE=false
+
+if "%INSTANCE_ROOT%" == "" goto setInstanceRoot
+
+:scriptBegin
+if "%SCRIPT_UTIL_CMD%" == "set-full-environment-and-test-java" goto setFullEnvironmentAndTestJava
+if "%SCRIPT_UTIL_CMD%" == "set-full-environment" goto setFullEnvironment
+if "%SCRIPT_UTIL_CMD%" == "set-java-home-and-args" goto setJavaHomeAndArgs
+if "%SCRIPT_UTIL_CMD%" == "set_environment_vars" goto setEnvironmentVars
+if "%SCRIPT_UTIL_CMD%" == "test-java" goto testJava
+if "%SCRIPT_UTIL_CMD%" == "set-classpath" goto setClassPath
+goto end
+
+:setInstanceRoot
+setlocal
+for %%i in (%~sf0) do set DIR_HOME=%%~dPsi..
+set INSTANCE_ROOT=%DIR_HOME%
+goto scriptBegin
+
+
+:setClassPath
+if "%SET_CLASSPATH_DONE%" == "true" goto end
+FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\lib\setcp.bat" %%x
+set CLASSPATH=%DIR_HOME%\classes;%CLASSPATH%
+set SET_CLASSPATH_DONE=true
+goto scriptBegin
+
+:setFullEnvironment
+if "%SET_JAVA_HOME_AND_ARGS_DONE%" == "false" goto setJavaHomeAndArgs
+if "%SET_CLASSPATH_DONE%" == "false" goto setClassPath
+if "%SET_ENVIRONMENT_VARS_DONE%" == "false" goto setEnvironmentVars
+goto end
+
+:setFullEnvironmentAndTestJava
+if "%SET_JAVA_HOME_AND_ARGS_DONE%" == "false" goto setJavaHomeAndArgs
+if "%SET_CLASSPATH_DONE%" == "false" goto setClassPath
+if "%SET_ENVIRONMENT_VARS_DONE%" == "false" goto setEnvironmentVars
+goto testJava
+
+
+:setJavaHomeAndArgs
+if "%SET_JAVA_HOME_AND_ARGS_DONE%" == "true" goto end
+if not exist "%DIR_HOME%\lib\set-java-home.bat" goto checkEnvJavaArgs
+call "%DIR_HOME%\lib\set-java-home.bat"
+if "%OPENDS_JAVA_BIN%" == "" goto checkEnvJavaArgs
+:endJavaHomeAndArgs
+set SET_JAVA_HOME_AND_ARGS_DONE=true
+goto scriptBegin
+
+:checkEnvJavaArgs
+if "%OPENDS_JAVA_ARGS%"=="" set OPENDS_JAVA_ARGS=%JAVA_ARGS%
+if "%OPENDS_JAVA_BIN%" == "" goto checkOpenDSJavaHome
+if not exist "%OPENDS_JAVA_BIN%" goto checkOpenDSJavaHome
+goto endJavaHomeAndArgs
+
+:checkOpenDSJavaHome
+if "%OPENDS_JAVA_HOME%" == "" goto checkJavaBin
+if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkJavaBin
+set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
+goto endJavaHomeAndArgs
+
+:checkJavaBin
+if "%JAVA_BIN%" == "" goto checkJavaHome
+if not exist "%JAVA_BIN%" goto checkJavaHome
+set OPENDS_JAVA_BIN=%JAVA_BIN%
+goto endJavaHomeAndArgs
+
+:checkJavaHome
+if "%JAVA_HOME%" == "" goto noJavaFound
+if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaFound
+set OPENDS_JAVA_BIN=%JAVA_HOME%\bin\java.exe
+goto endJavaHomeAndArgs
+
+:noJavaFound
+echo ERROR:  Could not find a valid java binary to be used.
+echo You must specify the path to a valid Java 5.0 or higher version.
+echo The procedure to follow is:
+echo 1. Delete the file %INSTANCE_ROOT%\lib\set-java-home.bat if it exists.
+echo 2. Set the environment variable OPENDS_JAVA_HOME to the root of a valid
+echo Java 5.0 installation.
+echo If you want to have specific java  settings for each command line you must
+echo follow the steps 3 and 4.
+echo 3. Edit the properties file specifying the java binary and the java arguments
+echo for each command line.  The java properties file is located in:
+echo %INSTANCE_ROOT%\config\java.properties.
+echo 4. Run the command-line %INSTANCE_ROOT%\bin\dsjavaproperties
+pause
+exit /B 1
+
+:setEnvironmentVars
+if %SET_ENVIRONMENT_VARS_DONE% == "true" goto end
+set PATH=%SystemRoot%
+set SCRIPT_NAME_ARG=-Dorg.opends.server.scriptName=%SCRIPT_NAME%
+set SET_ENVIRONMENT_VARS_DONE=true
+goto scriptBegin
+
+:testJava
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% org.opends.server.tools.InstallDS -t > NUL 2>&1
+if not %errorlevel% == 0 goto noValidJavaHome
+goto end
+
+:noValidJavaHome
+if NOT "%OPENDS_JAVA_ARGS%" == "" goto noValidHomeWithArgs
+echo ERROR:  The detected Java version could not be used.  The detected
+echo java binary is:
+echo %OPENDS_JAVA_BIN%
+echo You must specify the path to a valid Java 5.0 or higher version.
+echo The procedure to follow is:
+echo 1. Delete the file %INSTANCE_ROOT%\lib\set-java-home.bat if it exists.
+echo 2. Set the environment variable OPENDS_JAVA_HOME to the root of a valid
+echo Java 5.0 installation.
+echo If you want to have specific java  settings for each command line you must
+echo follow the steps 3 and 4.
+echo 3. Edit the properties file specifying the java binary and the java arguments
+echo for each command line.  The java properties file is located in:
+echo %INSTANCE_ROOT%\config\java.properties.
+echo 4. Run the command-line %INSTANCE_ROOT%\bin\dsjavaproperties
+pause
+exit /B 1
+
+:noValidHomeWithArgs
+echo ERROR:  The detected Java version could not be used with the set of java
+echo arguments %OPENDS_JAVA_ARGS%.
+echo The detected java binary is:
+echo %OPENDS_JAVA_BIN%
+echo You must specify the path to a valid Java 5.0 or higher version.
+echo The procedure to follow is:
+echo 1. Delete the file %INSTANCE_ROOT%\lib\set-java-home.bat if it exists.
+echo 2. Set the environment variable OPENDS_JAVA_HOME to the root of a valid
+echo Java 5.0 installation.
+echo If you want to have specific java  settings for each command line you must
+echo follow the steps 3 and 4.
+echo 3. Edit the properties file specifying the java binary and the java arguments
+echo for each command line.  The java properties file is located in:
+echo %INSTANCE_ROOT%\config\java.properties.
+echo 4. Run the command-line %INSTANCE_ROOT%\bin\dsjavaproperties
+pause
+exit /B 1
+
+:end
+exit /B 0
diff --git a/opends/resource/bin/_script-util.sh b/opends/resource/bin/_script-util.sh
new file mode 100644
index 0000000..dc001c0
--- /dev/null
+++ b/opends/resource/bin/_script-util.sh
@@ -0,0 +1,177 @@
+#!/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License").  You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at
+# trunk/opends/resource/legal-notices/OpenDS.LICENSE
+# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at
+# trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+# add the following below this CDDL HEADER, with the fields enclosed
+# by brackets "[]" replaced with your own identifying information:
+#      Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#      Portions Copyright 2007 Sun Microsystems, Inc.
+
+#
+# function that sets the java home
+#
+set_java_home_and_args() {
+  if test -f "${INSTANCE_ROOT}/lib/set-java-home"
+  then
+    . "${INSTANCE_ROOT}/lib/set-java-home"
+  elif test -z "${OPENDS_JAVA_BIN}"
+  then
+    if test -z "${OPENDS_JAVA_HOME}"
+    then
+      if test -z "${JAVA_BIN}"
+      then
+        if test -z "${JAVA_HOME}"
+        then
+          OPENDS_JAVA_BIN=`which java 2> /dev/null`
+          if test ${?} -eq 0
+          then
+            export OPENDS_JAVA_BIN
+          else
+            echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation"
+            echo "or edit the java.properties file and then run the dsjavaproperties script to"
+            echo "specify the java version to be used"
+            exit 1
+          fi
+        else
+          OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
+          export OPENDS_JAVA_BIN
+        fi
+      else
+        OPENDS_JAVA_BIN="${JAVA_BIN}"
+        export OPENDS_JAVA_BIN
+      fi
+    else
+      OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
+      export OPENDS_JAVA_BIN
+    fi
+  fi
+}
+
+# Determine whether the detected Java environment is acceptable for use. 
+test_java() {
+  if test -z "${OPENDS_JAVA_ARGS}"
+  then
+    "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
+    if test ${?} -ne 0
+    then
+      echo "ERROR:  The detected Java version could not be used.  The detected"
+      echo "java binary is:"
+      echo "${OPENDS_JAVA_BIN}"
+      echo "You must specify the path to a valid Java 5.0 or higher version."
+      echo "The procedure to follow is:"
+      echo "1. Delete the file ${INSTANCE_ROOT}/lib/set-java-home" if it exists.
+      echo "2. Set the environment variable OPENDS_JAVA_HOME to the root of a valid "
+      echo "Java 5.0 installation."
+      echo "If you want to have specific java  settings for each command line you must"
+      echo "follow the steps 3 and 4."
+      echo "3. Edit the properties file specifying the java binary and the java arguments"
+      echo "for each command line.  The java properties file is located in:"
+      echo "${INSTANCE_ROOT}/config/java.properties."
+      echo "4. Run the command-line ${INSTANCE_ROOT}/bin/dsjavaproperties"
+      exit 1
+    fi
+  else
+    "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
+    if test ${?} -ne 0
+    then
+      echo "ERROR:  The detected Java version could not be used with the set of java"
+      echo "arguments ${OPENDS_JAVA_ARGS}."
+      echo "The detected java binary is:"
+      echo "${OPENDS_JAVA_BIN}"
+      echo "You must specify the path to a valid Java 5.0 or higher version."
+      echo "The procedure to follow is:"
+      echo "1. Delete the file ${INSTANCE_ROOT}/lib/set-java-home" if it exists.
+      echo "2. Set the environment variable OPENDS_JAVA_HOME to the root of a valid "
+      echo "Java 5.0 installation."
+      echo "If you want to have specific java  settings for each command line you must"
+      echo "follow the steps 3 and 4."
+      echo "3. Edit the properties file specifying the java binary and the java arguments"
+      echo "for each command line.  The java properties file is located in:"
+      echo "${INSTANCE_ROOT}/config/java.properties."
+      echo "4. Run the command-line ${INSTANCE_ROOT}/bin/dsjavaproperties"
+      exit 1
+    fi
+  fi
+}
+
+# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
+# system environment variables for security and compatibility reasons.
+set_environment_vars() {
+  PATH=/bin:/usr/bin
+  LD_LIBRARY_PATH=
+  LD_LIBRARY_PATH_32=
+  LD_LIBRARY_PATH_64=
+  LD_PRELOAD=
+  LD_PRELOAD_32=
+  LD_PRELOAD_64=
+  export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
+       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
+  SCRIPT_NAME_ARG=-Dorg.opends.server.scriptName=${SCRIPT_NAME}
+	export SCRIPT_NAME_ARG
+}
+
+# Configure the appropriate CLASSPATH.
+set_classpath() {
+  CLASSPATH=${INSTANCE_ROOT}/classes
+  for JAR in ${INSTANCE_ROOT}/lib/*.jar
+  do
+    CLASSPATH=${CLASSPATH}:${JAR}
+  done
+  export CLASSPATH
+}
+
+if test "${INSTANCE_ROOT}" = ""
+then
+  # Capture the current working directory so that we can change to it later.
+  # Then capture the location of this script and the Directory Server instance
+  # root so that we can use them to create appropriate paths.
+  WORKING_DIR=`pwd`
+
+  cd `dirname "${0}"`
+  cd ..
+  INSTANCE_ROOT=`pwd`
+  cd "${WORKING_DIR}"
+fi
+
+if test "${SCRIPT_UTIL_CMD}" = "set-full-environment-and-test-java"
+then
+  set_java_home_and_args
+  set_environment_vars
+  set_classpath
+  test_java
+elif test "${SCRIPT_UTIL_CMD}" = "set-full-environment"
+then
+  set_java_home_and_args
+  set_environment_vars
+  set_classpath
+elif test "${SCRIPT_UTIL_CMD}" = "set-java-home-and-args"
+then
+  set_java_home_and_args
+elif test "${SCRIPT_UTIL_CMD}" = "set-environment-vars"
+then
+  set_environment_vars
+elif test "${SCRIPT_UTIL_CMD}" = "set-classpath"
+then
+  set_classpath
+elif test "${SCRIPT_UTIL_CMD}" = "test-java"
+then
+  test_java
+fi
diff --git a/opends/resource/bin/_server-script.bat b/opends/resource/bin/_server-script.bat
index 2c40404..f7b6a26 100644
--- a/opends/resource/bin/_server-script.bat
+++ b/opends/resource/bin/_server-script.bat
@@ -33,54 +33,19 @@
 set INSTANCE_ROOT=%DIR_HOME%
 
 if "%OPENDS_INVOKE_CLASS%" == "" goto noInvokeClass
-goto checkOpenDSJavaBin
+goto launchCommand
 
 :noInvokeClass
 echo Error:  OPENDS_INVOKE_CLASS environment variable is not set.
 pause
 goto end
 
-:checkOpenDSJavaBin
-if "%OPENDS_JAVA_BIN%" == "" goto checkOpenDSJavaHome
-goto setClassPath
+:launchCommand
+set SCRIPT_UTIL_CMD=set-full-environment
+call "%INSTANCE_ROOT%\lib\_script-util.bat"
+if NOT %errorlevel% == 0 exit /B %errorlevel%
 
-:checkOpenDSJavaHome
-if "%OPENDS_JAVA_HOME%" == "" goto checkOpenDSJavaHomeFile
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkOpenDSJavaHomeFile
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkOpenDSJavaHomeFile
-if not exist "%DIR_HOME%\lib\set-java-home.bat" goto checkJavaBin
-call "%DIR_HOME%\lib\set-java-home.bat"
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkJavaBin
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkJavaBin
-if "%JAVA_BIN%" == "" goto checkJavaHome
-set OPENDS_JAVA_BIN=%JAVA_BIN%
-goto setClassPath
-
-:checkJavaHome
-if "%JAVA_HOME%" == "" goto noJavaHome
-if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
-set OPENDS_JAVA_BIN=%JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:noJavaHome
-echo Error: OPENDS_JAVA_HOME environment variable is not set.
-echo        Please set it to a valid Java 5 (or later) installation.
-pause
-goto end
-
-:setClassPath
-FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\lib\setcp.bat" %%x
-
-set PATH=%SystemRoot%
-
-"%OPENDS_JAVA_BIN%" %JAVA_ARGS% %SCRIPT_NAME_ARG% %OPENDS_INVOKE_CLASS% --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
-
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG% %OPENDS_INVOKE_CLASS% --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
 
 :end
 
diff --git a/opends/resource/bin/_server-script.sh b/opends/resource/bin/_server-script.sh
index 830070a..1e1e73f 100755
--- a/opends/resource/bin/_server-script.sh
+++ b/opends/resource/bin/_server-script.sh
@@ -49,69 +49,17 @@
 
 cd "${WORKING_DIR}"
 
-
-# See if the environment variables are set.  If not, then see if there is a java
-# executable in the path and try to figure it out.
-if test -z "${OPENDS_JAVA_BIN}"
+# Set environment variables
+SCRIPT_UTIL_CMD=set-full-environment
+export SCRIPT_UTIL_CMD
+.  "${INSTANCE_ROOT}/lib/_script-util.sh"
+RETURN_CODE=$?
+if test ${RETURN_CODE} -ne 0
 then
-  if test -z "${OPENDS_JAVA_HOME}"
-  then
-    if test -f "${INSTANCE_ROOT}/lib/set-java-home"
-    then
-      . "${INSTANCE_ROOT}/lib/set-java-home"
-      OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-      export OPENDS_JAVA_BIN
-    else
-      if test -z "${JAVA_BIN}"
-      then
-        if test -z "${JAVA_HOME}"
-        then
-          OPENDS_JAVA_BIN=`which java 2> /dev/null`
-          if test ${?} -eq 0
-          then
-            export OPENDS_JAVA_BIN
-          else
-            echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-            exit 1
-          fi
-        else
-          OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
-          export OPENDS_JAVA_BIN
-        fi
-      else
-        OPENDS_JAVA_BIN="${JAVA_BIN}"
-        export OPENDS_JAVA_BIN
-      fi
-    fi
-  else
-    OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-    export OPENDS_JAVA_BIN
-  fi
+  exit ${RETURN_CODE}
 fi
 
-
-# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
-# system environment variables for security and compatibility reasons.
-PATH=/bin:/usr/bin
-LD_LIBRARY_PATH=
-LD_LIBRARY_PATH_32=
-LD_LIBRARY_PATH_64=
-LD_PRELOAD=
-LD_PRELOAD_32=
-LD_PRELOAD_64=
-export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
-       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
-
-
-# Configure the appropriate CLASSPATH.
-CLASSPATH=${INSTANCE_ROOT}/classes
-for JAR in ${INSTANCE_ROOT}/lib/*.jar
-do
-  CLASSPATH=${CLASSPATH}:${JAR}
-done
-export CLASSPATH
-
 # Launch the appropriate server utility.
-"${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} "${OPENDS_INVOKE_CLASS}" \
+"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} "${OPENDS_INVOKE_CLASS}" \
      --configClass org.opends.server.extensions.ConfigFileHandler \
      --configFile "${INSTANCE_ROOT}/config/config.ldif" "${@}"
diff --git a/opends/resource/bin/backup b/opends/resource/bin/backup
index c7fd119..d9046f5 100755
--- a/opends/resource/bin/backup
+++ b/opends/resource/bin/backup
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.BackUpDB"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=backup"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="backup"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
-"${SCRIPT_DIR}/../lib/_server-script.sh" "${@}"
+"${SCRIPT_DIR}/../lib/_mixed-script.sh" "${@}"
diff --git a/opends/resource/bin/backup.bat b/opends/resource/bin/backup.bat
index 44c4c5c..04dd8fb 100644
--- a/opends/resource/bin/backup.bat
+++ b/opends/resource/bin/backup.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.BackUpDB"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=backup"
-for %%i in (%~sf0) do call "%%~dPsi\..\lib\_server-script.bat" %*
+set SCRIPT_NAME=backup
+for %%i in (%~sf0) do call "%%~dPsi\..\lib\_mixed-script.bat" %*
 
diff --git a/opends/resource/bin/base64 b/opends/resource/bin/base64
index eb290f9..97f7fe1 100755
--- a/opends/resource/bin/base64
+++ b/opends/resource/bin/base64
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.util.Base64"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=base64"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="base64"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/base64.bat b/opends/resource/bin/base64.bat
index 233343e..0f0f3b3 100644
--- a/opends/resource/bin/base64.bat
+++ b/opends/resource/bin/base64.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.util.Base64"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=base64"
+set SCRIPT_NAME=base64
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
 
diff --git a/opends/resource/bin/create-rc-script b/opends/resource/bin/create-rc-script
index b958bab..d36d999 100644
--- a/opends/resource/bin/create-rc-script
+++ b/opends/resource/bin/create-rc-script
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.CreateRCScript"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=create-rc-script"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="create-rc-script"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/dbtest b/opends/resource/bin/dbtest
index 99fb90c..a304a91 100644
--- a/opends/resource/bin/dbtest
+++ b/opends/resource/bin/dbtest
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.DBTest"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=dbtest"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="dbtest"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_server-script.sh" "${@}"
diff --git a/opends/resource/bin/dbtest.bat b/opends/resource/bin/dbtest.bat
index a1beedd..a7c85a0 100644
--- a/opends/resource/bin/dbtest.bat
+++ b/opends/resource/bin/dbtest.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.DBTest"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=dbtest"
+set SCRIPT_NAME=dbtest
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_server-script.bat" %*
 
diff --git a/opends/resource/bin/dsconfig b/opends/resource/bin/dsconfig
index 9615ff8..09c6cd6 100755
--- a/opends/resource/bin/dsconfig
+++ b/opends/resource/bin/dsconfig
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.dsconfig.DSConfig"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=dsconfig"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="dsconfig"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/dsconfig.bat b/opends/resource/bin/dsconfig.bat
index 0ce932b..8af6d3d 100644
--- a/opends/resource/bin/dsconfig.bat
+++ b/opends/resource/bin/dsconfig.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.dsconfig.DSConfig"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=dsconfig"
+set SCRIPT_NAME=dsconfig
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
 
diff --git a/opends/resource/bin/dsframework b/opends/resource/bin/dsframework
index 0eb0e2b..b134425 100755
--- a/opends/resource/bin/dsframework
+++ b/opends/resource/bin/dsframework
@@ -31,8 +31,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.admin.client.cli.DsFrameworkCliMain"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=dsframework"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="dsframework"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/dsframework.bat b/opends/resource/bin/dsframework.bat
index 78dfd0f..73912eb 100644
--- a/opends/resource/bin/dsframework.bat
+++ b/opends/resource/bin/dsframework.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.admin.client.cli.DsFrameworkCliMain"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=dsframework"
+set SCRIPT_NAME=dsframework
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
 
diff --git a/opends/resource/bin/dsjavaproperties b/opends/resource/bin/dsjavaproperties
new file mode 100644
index 0000000..17baf08
--- /dev/null
+++ b/opends/resource/bin/dsjavaproperties
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License").  You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at
+# trunk/opends/resource/legal-notices/OpenDS.LICENSE
+# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at
+# trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+# add the following below this CDDL HEADER, with the fields enclosed
+# by brackets "[]" replaced with your own identifying information:
+#      Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#      Portions Copyright 2007 Sun Microsystems, Inc.
+
+
+# This script may be used to perform some replication specific operations.
+OPENDS_INVOKE_CLASS="org.opends.server.tools.JavaPropertiesTool"
+export OPENDS_INVOKE_CLASS
+
+SCRIPT_NAME="dsjavaproperties"
+export SCRIPT_NAME
+
+SCRIPT_DIR=`dirname "${0}"`
+"${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/dsjavaproperties.bat b/opends/resource/bin/dsjavaproperties.bat
new file mode 100644
index 0000000..4641d08
--- /dev/null
+++ b/opends/resource/bin/dsjavaproperties.bat
@@ -0,0 +1,32 @@
+
+@echo off
+rem CDDL HEADER START
+rem
+rem The contents of this file are subject to the terms of the
+rem Common Development and Distribution License, Version 1.0 only
+rem (the "License").  You may not use this file except in compliance
+rem with the License.
+rem
+rem You can obtain a copy of the license at
+rem trunk/opends/resource/legal-notices/OpenDS.LICENSE
+rem or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+rem See the License for the specific language governing permissions
+rem and limitations under the License.
+rem
+rem When distributing Covered Code, include this CDDL HEADER in each
+rem file and include the License file at
+rem trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+rem add the following below this CDDL HEADER, with the fields enclosed
+rem by brackets "[]" replaced with your own identifying information:
+rem      Portions Copyright [yyyy] [name of copyright owner]
+rem
+rem CDDL HEADER END
+rem
+rem
+rem      Portions Copyright 2007 Sun Microsystems, Inc.
+
+setlocal
+
+set OPENDS_INVOKE_CLASS="org.opends.server.tools.JavaPropertiesTool"
+set SCRIPT_NAME=dsjavaproperties
+for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
diff --git a/opends/resource/bin/dsreplication b/opends/resource/bin/dsreplication
index 280bfcb..a954be7 100644
--- a/opends/resource/bin/dsreplication
+++ b/opends/resource/bin/dsreplication
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.guitools.replicationcli.ReplicationCliMain"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=dsreplication"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="dsreplication"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/dsreplication.bat b/opends/resource/bin/dsreplication.bat
index 1e2aa0c..c9c1f16 100644
--- a/opends/resource/bin/dsreplication.bat
+++ b/opends/resource/bin/dsreplication.bat
@@ -28,5 +28,5 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.guitools.replicationcli.ReplicationCliMain"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=dsreplication"
+set SCRIPT_NAME=dsreplication
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
diff --git a/opends/resource/bin/encode-password b/opends/resource/bin/encode-password
index b0fec61..26af5e7 100755
--- a/opends/resource/bin/encode-password
+++ b/opends/resource/bin/encode-password
@@ -31,8 +31,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.EncodePassword"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=encode-password"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="encode-password"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_server-script.sh" "${@}"
diff --git a/opends/resource/bin/encode-password.bat b/opends/resource/bin/encode-password.bat
index 168e324..e2366c6 100644
--- a/opends/resource/bin/encode-password.bat
+++ b/opends/resource/bin/encode-password.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.EncodePassword"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=encode-password"
+set SCRIPT_NAME=encode-password
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_server-script.bat" %*
 
diff --git a/opends/resource/bin/export-ldif b/opends/resource/bin/export-ldif
index 21c4f9c..ce192b7 100755
--- a/opends/resource/bin/export-ldif
+++ b/opends/resource/bin/export-ldif
@@ -31,8 +31,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.ExportLDIF"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=export-ldif"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="export-ldif"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
-"${SCRIPT_DIR}/../lib/_server-script.sh" "${@}"
+"${SCRIPT_DIR}/../lib/_mixed-script.sh" "${@}"
diff --git a/opends/resource/bin/export-ldif.bat b/opends/resource/bin/export-ldif.bat
index e85aaaa..a0fd1ae 100644
--- a/opends/resource/bin/export-ldif.bat
+++ b/opends/resource/bin/export-ldif.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.ExportLDIF"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=export-ldif"
-for %%i in (%~sf0) do call "%%~dPsi\..\lib\_server-script.bat" %*
+set SCRIPT_NAME=export-ldif
+for %%i in (%~sf0) do call "%%~dPsi\..\lib\_mixed-script.bat" %*
 
diff --git a/opends/resource/bin/import-ldif b/opends/resource/bin/import-ldif
index 96e6fb8..cb8d974 100755
--- a/opends/resource/bin/import-ldif
+++ b/opends/resource/bin/import-ldif
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.ImportLDIF"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=import-ldif"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="import-ldif"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
-"${SCRIPT_DIR}/../lib/_server-script.sh" "${@}"
+"${SCRIPT_DIR}/../lib/_mixed-script.sh" "${@}"
diff --git a/opends/resource/bin/import-ldif.bat b/opends/resource/bin/import-ldif.bat
index d2000e8..5a24099 100644
--- a/opends/resource/bin/import-ldif.bat
+++ b/opends/resource/bin/import-ldif.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.ImportLDIF"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=import-ldif"
-for %%i in (%~sf0) do call "%%~dPsi\..\lib\_server-script.bat" %*
+set SCRIPT_NAME=import-ldif
+for %%i in (%~sf0) do call "%%~dPsi\..\lib\_mixed-script.bat" %*
 
diff --git a/opends/resource/bin/ldapcompare b/opends/resource/bin/ldapcompare
index fe2c466..7957013 100755
--- a/opends/resource/bin/ldapcompare
+++ b/opends/resource/bin/ldapcompare
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.LDAPCompare"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldapcompare"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="ldapcompare"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/ldapcompare.bat b/opends/resource/bin/ldapcompare.bat
index 7b91fd3..8143ae2 100644
--- a/opends/resource/bin/ldapcompare.bat
+++ b/opends/resource/bin/ldapcompare.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.LDAPCompare"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldapcompare"
+set SCRIPT_NAME=ldapcompare
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
 
diff --git a/opends/resource/bin/ldapdelete b/opends/resource/bin/ldapdelete
index dce0b82..d49da69 100755
--- a/opends/resource/bin/ldapdelete
+++ b/opends/resource/bin/ldapdelete
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.LDAPDelete"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldapdelete"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="ldapdelete"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/ldapdelete.bat b/opends/resource/bin/ldapdelete.bat
index 53d63b8..66452c1 100644
--- a/opends/resource/bin/ldapdelete.bat
+++ b/opends/resource/bin/ldapdelete.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.LDAPDelete"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldapdelete"
+set SCRIPT_NAME=ldapdelete
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
 
diff --git a/opends/resource/bin/ldapmodify b/opends/resource/bin/ldapmodify
index 0ecf40e..98f247f 100755
--- a/opends/resource/bin/ldapmodify
+++ b/opends/resource/bin/ldapmodify
@@ -31,8 +31,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.LDAPModify"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldapmodify"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="ldapmodify"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/ldapmodify.bat b/opends/resource/bin/ldapmodify.bat
index 0297aa6..34f339a 100644
--- a/opends/resource/bin/ldapmodify.bat
+++ b/opends/resource/bin/ldapmodify.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.LDAPModify"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldapmodify"
+set SCRIPT_NAME=ldapmodify
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
 
diff --git a/opends/resource/bin/ldappasswordmodify b/opends/resource/bin/ldappasswordmodify
index 706e84f..f0e1c51 100755
--- a/opends/resource/bin/ldappasswordmodify
+++ b/opends/resource/bin/ldappasswordmodify
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.LDAPPasswordModify"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldappasswordmodify"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="ldappasswordmodify"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/ldappasswordmodify.bat b/opends/resource/bin/ldappasswordmodify.bat
index 82cab36..d264150 100644
--- a/opends/resource/bin/ldappasswordmodify.bat
+++ b/opends/resource/bin/ldappasswordmodify.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.LDAPPasswordModify"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldappasswordmodify"
+set SCRIPT_NAME=ldappasswordmodify
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
 
diff --git a/opends/resource/bin/ldapsearch b/opends/resource/bin/ldapsearch
index a745977..d3ad261 100755
--- a/opends/resource/bin/ldapsearch
+++ b/opends/resource/bin/ldapsearch
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.LDAPSearch"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldapsearch"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="ldapsearch"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/ldapsearch.bat b/opends/resource/bin/ldapsearch.bat
index b98f53c..ba3e552 100644
--- a/opends/resource/bin/ldapsearch.bat
+++ b/opends/resource/bin/ldapsearch.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.LDAPSearch"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldapsearch"
+set SCRIPT_NAME=ldapsearch
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
 
diff --git a/opends/resource/bin/ldif-diff b/opends/resource/bin/ldif-diff
index a197671..ccaaed4 100755
--- a/opends/resource/bin/ldif-diff
+++ b/opends/resource/bin/ldif-diff
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.LDIFDiff"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldif-diff"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="ldif-diff"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/ldif-diff.bat b/opends/resource/bin/ldif-diff.bat
index 0a7b893..60d6e47 100644
--- a/opends/resource/bin/ldif-diff.bat
+++ b/opends/resource/bin/ldif-diff.bat
@@ -28,7 +28,7 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.LDIFDiff"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldif-diff"
+set SCRIPT_NAME_ARG=ldif-diff
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
 
 
diff --git a/opends/resource/bin/ldifmodify b/opends/resource/bin/ldifmodify
index 64e398b..a81778d 100755
--- a/opends/resource/bin/ldifmodify
+++ b/opends/resource/bin/ldifmodify
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.LDIFModify"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldifmodify"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="ldifmodify"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_server-script.sh" "${@}"
diff --git a/opends/resource/bin/ldifmodify.bat b/opends/resource/bin/ldifmodify.bat
index d524ab4..f3f9c4a 100644
--- a/opends/resource/bin/ldifmodify.bat
+++ b/opends/resource/bin/ldifmodify.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.LDIFModify"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldifmodify"
+set SCRIPT_NAME_ARG=ldifmodify
 for %%i in (%~sf0) do  call "%%~dPsi\..\lib\_server-script.bat" %*
 
diff --git a/opends/resource/bin/ldifsearch b/opends/resource/bin/ldifsearch
index d4c4be5..a8c50ad 100755
--- a/opends/resource/bin/ldifsearch
+++ b/opends/resource/bin/ldifsearch
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.LDIFSearch"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldifsearch"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="ldifsearch"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_server-script.sh" "${@}"
diff --git a/opends/resource/bin/ldifsearch.bat b/opends/resource/bin/ldifsearch.bat
index 48f52a7..11d5e1f 100644
--- a/opends/resource/bin/ldifsearch.bat
+++ b/opends/resource/bin/ldifsearch.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.LDIFSearch"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=ldifsearch"
+set SCRIPT_NAME=ldifsearch
 for %%i in (%~sf0) do  call "%%~dPsi\..\lib\_server-script.bat" %*
 
diff --git a/opends/resource/bin/list-backends b/opends/resource/bin/list-backends
index 4d1eef4..5eb2f33 100755
--- a/opends/resource/bin/list-backends
+++ b/opends/resource/bin/list-backends
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.ListBackends"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=list-backends"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="list-backends"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_server-script.sh" "${@}"
diff --git a/opends/resource/bin/list-backends.bat b/opends/resource/bin/list-backends.bat
index f77fb6e..fb9ddcd 100644
--- a/opends/resource/bin/list-backends.bat
+++ b/opends/resource/bin/list-backends.bat
@@ -28,7 +28,7 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.ListBackends"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=list-backends"
+set SCRIPT_NAME=list-backends
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_server-script.bat" %*
 
 
diff --git a/opends/resource/bin/make-ldif b/opends/resource/bin/make-ldif
index cb0d531..c53e396 100755
--- a/opends/resource/bin/make-ldif
+++ b/opends/resource/bin/make-ldif
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.makeldif.MakeLDIF"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=make-ldif"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="make-ldif"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_server-script.sh" \
diff --git a/opends/resource/bin/make-ldif.bat b/opends/resource/bin/make-ldif.bat
index f842b0e..efde244 100644
--- a/opends/resource/bin/make-ldif.bat
+++ b/opends/resource/bin/make-ldif.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.makeldif.MakeLDIF"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=make-ldif"
+set SCRIPT_NAME=make-ldif
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_server-script.bat" --resourcePath "%%~dPsi..\config\MakeLDIF" %*
 
diff --git a/opends/resource/bin/manage-account b/opends/resource/bin/manage-account
index 8e55ace..2441190 100755
--- a/opends/resource/bin/manage-account
+++ b/opends/resource/bin/manage-account
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.ManageAccount"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=manage-account"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="manage-account"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/manage-account.bat b/opends/resource/bin/manage-account.bat
index 13ad037..391c9fd 100644
--- a/opends/resource/bin/manage-account.bat
+++ b/opends/resource/bin/manage-account.bat
@@ -28,7 +28,7 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.ManageAccount"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=manage-account"
+set SCRIPT_NAME=manage-account
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %* 
 
 
diff --git a/opends/resource/bin/manage-tasks b/opends/resource/bin/manage-tasks
index dc53cf2..62f2512 100644
--- a/opends/resource/bin/manage-tasks
+++ b/opends/resource/bin/manage-tasks
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.ManageTasks"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=manage-tasks"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="manage-tasks"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/manage-tasks.bat b/opends/resource/bin/manage-tasks.bat
index 7edaaf1..227e680 100644
--- a/opends/resource/bin/manage-tasks.bat
+++ b/opends/resource/bin/manage-tasks.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.ManageTasks"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=manage-tasks"
+set SCRIPT_NAME=manage-tasks
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
 
diff --git a/opends/resource/bin/rebuild-index b/opends/resource/bin/rebuild-index
index 00aa7aa..6cb67a9 100644
--- a/opends/resource/bin/rebuild-index
+++ b/opends/resource/bin/rebuild-index
@@ -31,8 +31,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.RebuildIndex"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=rebuild-index"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="rebuild-index"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_server-script.sh" "${@}"
diff --git a/opends/resource/bin/rebuild-index.bat b/opends/resource/bin/rebuild-index.bat
index ad45e31..ec2c7c2 100644
--- a/opends/resource/bin/rebuild-index.bat
+++ b/opends/resource/bin/rebuild-index.bat
@@ -28,7 +28,7 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.RebuildIndex"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=rebuild-index"
+set SCRIPT_NAME=rebuild-index
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_server-script.bat" %*
 
 
diff --git a/opends/resource/bin/restore b/opends/resource/bin/restore
index 8e07646..4731b68 100755
--- a/opends/resource/bin/restore
+++ b/opends/resource/bin/restore
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.RestoreDB"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=restore"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="restore"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
-"${SCRIPT_DIR}/../lib/_server-script.sh" "${@}"
+"${SCRIPT_DIR}/../lib/_mixed-script.sh" "${@}"
diff --git a/opends/resource/bin/restore.bat b/opends/resource/bin/restore.bat
index 47f4813..6f86a58 100644
--- a/opends/resource/bin/restore.bat
+++ b/opends/resource/bin/restore.bat
@@ -28,7 +28,7 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.RestoreDB"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=restore"
-for %%i in (%~sf0) do call "%%~dPsi\..\lib\_server-script.bat" %*
+set SCRIPT_NAME=restore
+for %%i in (%~sf0) do call "%%~dPsi\..\lib\_mixed-script.bat" %*
 
 
diff --git a/opends/resource/bin/start-ds b/opends/resource/bin/start-ds
index 983f4fc..85743c8 100755
--- a/opends/resource/bin/start-ds
+++ b/opends/resource/bin/start-ds
@@ -40,69 +40,6 @@
 
 cd "${WORKING_DIR}"
 
-
-# See if the environment variables are set.  If not, then see if there is a java
-# executable in the path and try to figure it out.
-if test -z "${OPENDS_JAVA_BIN}"
-then
-  if test -z "${OPENDS_JAVA_HOME}"
-  then
-    if test -f "${INSTANCE_ROOT}/lib/set-java-home"
-    then
-      . "${INSTANCE_ROOT}/lib/set-java-home"
-      OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-      export OPENDS_JAVA_BIN
-    else
-      if test -z "${JAVA_BIN}"
-      then
-        if test -z "${JAVA_HOME}"
-        then
-          OPENDS_JAVA_BIN=`which java 2> /dev/null`
-          if test ${?} -eq 0
-          then
-            export OPENDS_JAVA_BIN
-          else
-            echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-            exit 1
-          fi
-        else
-          OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
-          export OPENDS_JAVA_BIN
-        fi
-      else
-        OPENDS_JAVA_BIN="${JAVA_BIN}"
-        export OPENDS_JAVA_BIN
-      fi
-    fi
-  else
-    OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-    export OPENDS_JAVA_BIN
-  fi
-fi
-
-
-# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
-# system environment variables for security and compatibility reasons.
-PATH=/bin:/usr/bin
-LD_LIBRARY_PATH=
-LD_LIBRARY_PATH_32=
-LD_LIBRARY_PATH_64=
-LD_PRELOAD=
-LD_PRELOAD_32=
-LD_PRELOAD_64=
-export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
-       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
-
-
-# Configure the appropriate CLASSPATH.
-CLASSPATH=${INSTANCE_ROOT}/classes
-for JAR in ${INSTANCE_ROOT}/lib/*.jar
-do
-  CLASSPATH=${CLASSPATH}:${JAR}
-done
-export CLASSPATH
-
-
 # Specify the locations of important files that may be used when the server
 # is starting.
 CONFIG_FILE=${INSTANCE_ROOT}/config/config.ldif
@@ -112,33 +49,20 @@
 
 
 # Specify the script name so that it may be provided in command-line usage.
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=start-ds"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="start-ds"
+export SCRIPT_NAME
 
-# Test that the provided JDK is 1.5 compatible.
-if test -z "${JAVA_ARGS}"
+# Set environment variables
+SCRIPT_UTIL_CMD=set-full-environment-and-test-java
+export SCRIPT_UTIL_CMD
+.  "${INSTANCE_ROOT}/lib/_script-util.sh"
+RETURN_CODE=$?
+if test ${RETURN_CODE} -ne 0
 then
-  "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
-  if test ${?} -ne 0
-  then
-    echo "ERROR:  The detected Java version could not be used.  Please ensure"
-    echo "        that OPENDS_JAVA_HOME is set to the root of a valid Java 5.0 or"
-    echo "        higher installation."
-    exit 1
-  fi
-else
-  "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
-  if test ${?} -ne 0
-  then
-    echo "ERROR:  The detected Java version could not be used with the"
-    echo "        set of arguments.  Please ensure that OPENDS_JAVA_HOME is"
-    echo "        set to the root of a valid Java 5.0 or higher installation, and"
-    echo "        make sure that JAVA_ARGS contains a valid set of arguments"
-    echo "        for that JVM."
-    exit 1
-  fi
+	exit ${RETURN_CODE}
 fi
 
+
 # See if the provided set of arguments were sufficient for us to be able to
 # start the server or perform the requested operation.  An exit code of 99
 # means that it should be possible to start the server.  An exit code of 98
@@ -155,7 +79,7 @@
   # run detach
   #
   touch "${STARTING_FILE}"
-  nohup "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
+  nohup "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
        org.opends.server.core.DirectoryServer \
        --configClass org.opends.server.extensions.ConfigFileHandler \
        --configFile "${CONFIG_FILE}" "${@}" > "${LOG_FILE}" 2>&1 &
@@ -193,7 +117,7 @@
     #
     echo $$ > "${PID_FILE}"
     rm -f "${LOG_FILE}"
-    exec "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
+    exec "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
       org.opends.server.core.DirectoryServer \
       --configClass org.opends.server.extensions.ConfigFileHandler \
       --configFile "${CONFIG_FILE}" "${@}"
diff --git a/opends/resource/bin/start-ds.bat b/opends/resource/bin/start-ds.bat
index 538f28a..b197ee9 100644
--- a/opends/resource/bin/start-ds.bat
+++ b/opends/resource/bin/start-ds.bat
@@ -36,49 +36,12 @@
 
 echo %SCRIPT%: invoked >> %LOG%
 
-:checkOpenDSJavaBin
-if "%OPENDS_JAVA_BIN%" == "" goto checkOpenDSJavaHome
-goto setClassPath
+set SCRIPT_NAME=start-ds
 
-:checkOpenDSJavaHome
-if "%OPENDS_JAVA_HOME%" == "" goto checkOpenDSJavaHomeFile
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkOpenDSJavaHomeFile
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkOpenDSJavaHomeFile
-if not exist "%DIR_HOME%\lib\set-java-home.bat" goto checkJavaBin
-call "%DIR_HOME%\lib\set-java-home.bat"
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkJavaBin
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkJavaBin
-if "%JAVA_BIN%" == "" goto checkJavaHome
-set OPENDS_JAVA_BIN=%JAVA_BIN%
-goto setClassPath
-
-:checkJavaHome
-if "%JAVA_HOME%" == "" goto noJavaHome
-if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
-set OPENDS_JAVA_BIN=%JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:noJavaHome
-echo Error: OPENDS_JAVA_HOME environment variable is not set.
-echo        Please set it to a valid Java 5 (or later) installation.
-pause
-goto end
-
-:noValidJavaHome
-echo %SCRIPT%: The detected Java version could not be used. OPENDS_JAVA_HOME=[%OPENDS_JAVA_HOME%] >> %LOG%
-echo ERROR:  The detected Java version could not be used.  Please set 
-echo         OPENDS_JAVA_HOME to to a valid Java 5 (or later) installation.
-pause
-goto end
-
-:setClassPath
-FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\lib\setcp.bat" %%x
+rem Set environment variables
+set SCRIPT_UTIL_CMD=set-full-environment-and-test-java
+call "%INSTANCE_ROOT%\lib\_script-util.bat"
+if NOT %errorlevel% == 0 exit /B %errorlevel%
 
 echo %SCRIPT%: CLASSPATH=%CLASSPATH% >> %LOG%
 
@@ -86,12 +49,6 @@
 
 echo %SCRIPT%: PATH=%PATH% >> %LOG%
 
-set SCRIPT_NAME_ARG=-Dorg.opends.server.scriptName=start-ds
-
-rem Test that the provided JDK is 1.5 compatible.
-"%OPENDS_JAVA_BIN%" org.opends.server.tools.InstallDS -t > NUL 2>&1
-if not %errorlevel% == 0 goto noValidJavaHome
-
 "%OPENDS_JAVA_BIN%" -Xms8M -Xmx8M org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" --checkStartability %*
 
 if %errorlevel% == 98 goto serverAlreadyStarted
@@ -109,7 +66,8 @@
 echo %SCRIPT%: Run no detach  >> %LOG%
 if not exist "%DIR_HOME%\logs\server.out" echo. > "%DIR_HOME%\logs\server.out"
 if not exist "%DIR_HOME%\logs\server.starting" echo. > "%DIR_HOME%\logs\server.starting"
-"%OPENDS_JAVA_BIN%" %JAVA_ARGS% org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
+if exist "%DIR_HOME%\lib\set-java-args.bat %SCRIPT%" DO call "%DIR_HOME%\lib\set-java-args.bat"
+"%OPENDS_JAVA_BIN%" %OPENDS_SERVER_JAVA_ARGS% org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
 goto end
 
 
@@ -117,7 +75,8 @@
 echo %SCRIPT%: Run detach  >> %LOG%
 if not exist "%DIR_HOME%\logs\server.out" echo. > "%DIR_HOME%\logs\server.out"
 if not exist "%DIR_HOME%\logs\server.starting" echo. > "%DIR_HOME%\logs\server.starting"
-"%DIR_HOME%\lib\winlauncher.exe" start "%DIR_HOME%" "%OPENDS_JAVA_BIN%" %JAVA_ARGS%  org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
+if exist "%DIR_HOME%\lib\set-java-args.bat" DO call "%DIR_HOME%\lib\set-java-args.bat"
+"%DIR_HOME%\lib\winlauncher.exe" start "%DIR_HOME%" "%OPENDS_JAVA_BIN%" %OPENDS_SERVER_JAVA_ARGS%  org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
 echo %SCRIPT%: Waiting for "%DIR_HOME%\logs\server.out" to be deleted >> %LOG%
 "%OPENDS_JAVA_BIN%" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete --targetFile "%DIR_HOME%\logs\server.starting" --logFile "%DIR_HOME%\logs\server.out"
 goto checkStarted
@@ -129,7 +88,8 @@
 if not exist "%DIR_HOME%\logs\server.starting" echo. > "%DIR_HOME%\logs\server.starting"
 echo. > "%DIR_HOME%\logs\server.startingservice"
 echo. > "%DIR_HOME%\logs\winservice.out"
-"%DIR_HOME%\lib\winlauncher.exe" start "%DIR_HOME%" "%OPENDS_JAVA_BIN%" -Xrs %JAVA_ARGS%  org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
+if exist "%DIR_HOME%\lib\set-java-args.bat" DO call "%DIR_HOME%\lib\set-java-args.bat"
+"%DIR_HOME%\lib\winlauncher.exe" start "%DIR_HOME%" "%OPENDS_JAVA_BIN%" -Xrs %OPENDS_SERVER_JAVA_ARGS%  org.opends.server.core.DirectoryServer --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
 echo %SCRIPT%: Waiting for "%DIR_HOME%\logs\server.out" to be deleted >> %LOG%
 "%OPENDS_JAVA_BIN%" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete --targetFile "%DIR_HOME%\logs\server.starting" --logFile "%DIR_HOME%\logs\server.out" --outputFile "%DIR_HOME%\logs\winservice.out"
 erase "%DIR_HOME%\logs\server.startingservice"
diff --git a/opends/resource/bin/status b/opends/resource/bin/status
index 5f2d450..780a568 100644
--- a/opends/resource/bin/status
+++ b/opends/resource/bin/status
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.guitools.statuspanel.StatusCli"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=status"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="status"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/status-panel b/opends/resource/bin/status-panel
index 46b808b..1897182 100644
--- a/opends/resource/bin/status-panel
+++ b/opends/resource/bin/status-panel
@@ -30,8 +30,8 @@
 OPENDS_INVOKE_CLASS="org.opends.guitools.statuspanel.StatusPanelLauncher"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=status-panel"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="status-panel"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_client-script.sh" "${@}"
diff --git a/opends/resource/bin/status-panel.bat b/opends/resource/bin/status-panel.bat
index 738ea93..e34c899 100644
--- a/opends/resource/bin/status-panel.bat
+++ b/opends/resource/bin/status-panel.bat
@@ -30,54 +30,24 @@
 
 set INSTANCE_ROOT=%DIR_HOME%
 
-:checkOpenDSJavaBin
-if "%OPENDS_JAVA_BIN%" == "" goto checkOpenDSJavaHome
-goto setClassPath
+set SCRIPT_NAME=status-panel
 
-:checkOpenDSJavaHome
-if "%OPENDS_JAVA_HOME%" == "" goto checkOpenDSJavaHomeFile
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkOpenDSJavaHomeFile
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkOpenDSJavaHomeFile
-if not exist "%DIR_HOME%\lib\set-java-home.bat" goto checkJavaBin
-call "%DIR_HOME%\lib\set-java-home.bat"
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkJavaBin
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkJavaBin
-if "%JAVA_BIN%" == "" goto checkJavaHome
-set OPENDS_JAVA_BIN=%JAVA_BIN%
-goto setClassPath
-
-:checkJavaHome
-if "%JAVA_HOME%" == "" goto noJavaHome
-if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
-set OPENDS_JAVA_BIN=%JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:noJavaHome
-echo Error: OPENDS_JAVA_HOME environment variable is not set.
-echo        Please set it to a valid Java 5 (or later) installation.
-pause
-goto end
-
-:setClassPath
-FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\lib\setcp.bat" %%x
-
-set PATH=%SystemRoot%
+rem Set environment variables
+set SCRIPT_UTIL_CMD=set-full-environment
+call "%INSTANCE_ROOT%\lib\_script-util.bat"
+if NOT %errorlevel% == 0 exit /B %errorlevel%
 
 if "%~1" == "" goto callLaunch
 goto callJava
 
 :callLaunch
-"%DIR_HOME%\lib\winlauncher.exe" launch "%OPENDS_JAVA_BIN%" %JAVA_ARGS% org.opends.guitools.statuspanel.StatusPanelLauncher
+if exist "%DIR_HOME%\lib\set-java-args.bat" DO call "%DIR_HOME%\lib\set-java-args.bat"
+"%DIR_HOME%\lib\winlauncher.exe" launch "%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG% org.opends.guitools.statuspanel.StatusPanelLauncher
 goto end
 
 :callJava
-"%OPENDS_JAVA_BIN%" %JAVA_ARGS% org.opends.guitools.statuspanel.StatusPanelLauncher %*
+if exist "%DIR_HOME%\lib\set-java-args.bat" DO call "%DIR_HOME%\lib\set-java-args.bat"
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG% org.opends.guitools.statuspanel.StatusPanelLauncher %*
 
 rem return part
 if %errorlevel% == 50 goto version
diff --git a/opends/resource/bin/status.bat b/opends/resource/bin/status.bat
index 84df965..d2a587a 100644
--- a/opends/resource/bin/status.bat
+++ b/opends/resource/bin/status.bat
@@ -28,5 +28,5 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.guitools.statuspanel.StatusCli"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=status"
+set SCRIPT_NAME=status
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
diff --git a/opends/resource/bin/stop-ds b/opends/resource/bin/stop-ds
index b16faa8..4fd2f01 100755
--- a/opends/resource/bin/stop-ds
+++ b/opends/resource/bin/stop-ds
@@ -50,92 +50,24 @@
 cd "${WORKING_DIR}"
 
 
-# See if the environment variables are set.  If not, then see if there is a java
-# executable in the path and try to figure it out.
-if test -z "${OPENDS_JAVA_BIN}"
+
+
+
+# Specify the script name so that we can use the specified java properties.
+SCRIPT_NAME="stop-ds"
+export SCRIPT_NAME
+
+# Set environment variables
+SCRIPT_UTIL_CMD=set-full-environment-and-test-java
+export SCRIPT_UTIL_CMD
+.  "${INSTANCE_ROOT}/lib/_script-util.sh"
+RETURN_CODE=$?
+if test ${RETURN_CODE} -ne 0
 then
-  if test -z "${OPENDS_JAVA_HOME}"
-  then
-    if test -f "${INSTANCE_ROOT}/lib/set-java-home"
-    then
-      . "${INSTANCE_ROOT}/lib/set-java-home"
-      OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-      export OPENDS_JAVA_BIN
-    else
-      if test -z "${JAVA_BIN}"
-      then
-        if test -z "${JAVA_HOME}"
-        then
-          OPENDS_JAVA_BIN=`which java 2> /dev/null`
-          if test ${?} -eq 0
-          then
-            export OPENDS_JAVA_BIN
-          else
-            echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-            exit 1
-          fi
-        else
-          OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
-          export OPENDS_JAVA_BIN
-        fi
-      else
-        OPENDS_JAVA_BIN="${JAVA_BIN}"
-        export OPENDS_JAVA_BIN
-      fi
-    fi
-  else
-    OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-    export OPENDS_JAVA_BIN
-  fi
+  exit ${RETURN_CODE}
 fi
 
 
-# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
-# system environment variables for security and compatibility reasons.
-PATH=/bin:/usr/bin
-LD_LIBRARY_PATH=
-LD_LIBRARY_PATH_32=
-LD_LIBRARY_PATH_64=
-LD_PRELOAD=
-LD_PRELOAD_32=
-LD_PRELOAD_64=
-export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
-       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
-
-
-# Configure the appropriate CLASSPATH.
-CLASSPATH=${INSTANCE_ROOT}/classes
-for JAR in ${INSTANCE_ROOT}/lib/*.jar
-do
-  CLASSPATH=${CLASSPATH}:${JAR}
-done
-export CLASSPATH
-
-
-# Specify the script name so that it may be provided in command-line usage.
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=stop-ds"
-export SCRIPT_NAME_ARG
-
-# Test that the provided JDK is 1.5 compatible.
-if test -z "${JAVA_ARGS}"
-then
-  "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
-  if test ${?} -ne 0
-  then
-    echo "ERROR:  The detected Java version could not be used.  Please set "
-    echo "        JAVA_HOME to the root of a Java 5.0 installation."
-    exit 1
-  fi
-else
-  "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
-  if test ${?} -ne 0
-  then
-    echo "ERROR:  The detected Java version could not be used with the specified"
-    echo "Java arguments.  Please set  OPENDS_JAVA_HOME to the root of a Java 5.0 installation."
-    exit 1
-  fi
-fi
-
 "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
   org.opends.server.tools.StopDS --checkStoppability "${@}"
 EC=${?}
diff --git a/opends/resource/bin/stop-ds.bat b/opends/resource/bin/stop-ds.bat
index 558c100..b18a3a3 100644
--- a/opends/resource/bin/stop-ds.bat
+++ b/opends/resource/bin/stop-ds.bat
@@ -42,56 +42,15 @@
 rem echo %SCRIPT%: your-message-here >> %LOG%
 echo %SCRIPT%: invoked >> %LOG%
 
-:checkOpenDSJavaBin
-if "%OPENDS_JAVA_BIN%" == "" goto checkOpenDSJavaHome
-goto setClassPath
+set SCRIPT_NAME=start-ds
 
-:checkOpenDSJavaHome
-if "%OPENDS_JAVA_HOME%" == "" goto checkOpenDSJavaHomeFile
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkOpenDSJavaHomeFile
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkOpenDSJavaHomeFile
-if not exist "%DIR_HOME%\lib\set-java-home.bat" goto checkJavaBin
-call "%DIR_HOME%\lib\set-java-home.bat"
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkJavaBin
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkJavaBin
-if "%JAVA_BIN%" == "" goto checkJavaHome
-set OPENDS_JAVA_BIN=%JAVA_BIN%
-goto setClassPath
-
-:checkJavaHome
-if "%JAVA_HOME%" == "" goto noJavaHome
-if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
-set OPENDS_JAVA_BIN=%JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:noJavaHome
-echo Error: OPENDS_JAVA_HOME environment variable is not set.
-echo        Please set it to a valid Java 5 (or later) installation.
-pause
-goto end
-
-:noValidJavaHome
-echo %SCRIPT%: The detected Java version could not be used. OPENDS_JAVA_HOME=[%OPENDS_JAVA_HOME%] >> %LOG%
-echo ERROR:  The detected Java version could not be used.  Please set 
-echo         OPENDS_JAVA_HOME to to a valid Java 5 (or later) installation.
-pause
-goto end
-
-:setClassPath
-FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\lib\setcp.bat" %%x
+rem Set environment variables
+set SCRIPT_UTIL_CMD=set-full-environment-and-test-java
+call "%INSTANCE_ROOT%\lib\_script-util.bat"
+if NOT %errorlevel% == 0 exit /B %errorlevel%
 
 echo %SCRIPT%: CLASSPATH=%CLASSPATH% >> %LOG%
 
-rem Test that the provided JDK is 1.5 compatible.
-"%OPENDS_JAVA_BIN%" org.opends.server.tools.InstallDS -t > NUL 2>&1
-if not %errorlevel% == 0 goto noValidJavaHome
-
 "%OPENDS_JAVA_BIN%" -Xms8M -Xmx8M %SCRIPT_NAME_ARG%  org.opends.server.tools.StopDS --checkStoppability %*
 
 if %errorlevel% == 98 goto serverAlreadyStopped
diff --git a/opends/resource/bin/verify-index b/opends/resource/bin/verify-index
index 187c53b..94edb4f 100755
--- a/opends/resource/bin/verify-index
+++ b/opends/resource/bin/verify-index
@@ -31,8 +31,8 @@
 OPENDS_INVOKE_CLASS="org.opends.server.tools.VerifyIndex"
 export OPENDS_INVOKE_CLASS
 
-SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=verify-index"
-export SCRIPT_NAME_ARG
+SCRIPT_NAME="verify-index"
+export SCRIPT_NAME
 
 SCRIPT_DIR=`dirname "${0}"`
 "${SCRIPT_DIR}/../lib/_server-script.sh" "${@}"
diff --git a/opends/resource/bin/verify-index.bat b/opends/resource/bin/verify-index.bat
index 59e8a39..5f1d2b9 100644
--- a/opends/resource/bin/verify-index.bat
+++ b/opends/resource/bin/verify-index.bat
@@ -28,7 +28,7 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.VerifyIndex"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=verify-index"
+set SCRIPT_NAME=verify-index
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_server-script.bat" %*
 
 
diff --git a/opends/resource/bin/windows-service.bat b/opends/resource/bin/windows-service.bat
index d03aa72..e2d5427 100644
--- a/opends/resource/bin/windows-service.bat
+++ b/opends/resource/bin/windows-service.bat
@@ -28,6 +28,6 @@
 setlocal
 
 set OPENDS_INVOKE_CLASS="org.opends.server.tools.ConfigureWindowsService"
-set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=windows-service"
+set SCRIPT_NAME=windows-service
 for %%i in (%~sf0) do call "%%~dPsi\..\lib\_client-script.bat" %*
 
diff --git a/opends/resource/setup b/opends/resource/setup
index 1109c86..ac47fcb 100755
--- a/opends/resource/setup
+++ b/opends/resource/setup
@@ -37,99 +37,23 @@
 INSTANCE_ROOT=${SCRIPT_DIR}
 export INSTANCE_ROOT
 
+SCRIPT_NAME=setup
+export SCRIPT_NAME
+
 cd "${WORKING_DIR}"
 
-# See if the environment variables are set.  If not, then see if there is a java
-# executable in the path and try to figure it out.
-if test -z "${OPENDS_JAVA_BIN}"
+# Set environment variables
+SCRIPT_UTIL_CMD=set-full-environment-and-test-java
+export SCRIPT_UTIL_CMD
+.  "${INSTANCE_ROOT}/lib/_script-util.sh"
+RETURN_CODE=$?
+if test ${RETURN_CODE} -ne 0
 then
-  if test -z "${OPENDS_JAVA_HOME}"
-  then
-    if test -f "${INSTANCE_ROOT}/lib/set-java-home"
-    then
-      . "${INSTANCE_ROOT}/lib/set-java-home"
-      OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-      export OPENDS_JAVA_BIN
-    else
-      if test -z "${JAVA_BIN}"
-      then
-        if test -z "${JAVA_HOME}"
-        then
-          OPENDS_JAVA_BIN=`which java 2> /dev/null`
-          if test ${?} -eq 0
-          then
-            export OPENDS_JAVA_BIN
-          else
-            echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-            exit 1
-          fi
-        else
-          OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
-          export OPENDS_JAVA_BIN
-        fi
-      else
-        OPENDS_JAVA_BIN="${JAVA_BIN}"
-        export OPENDS_JAVA_BIN
-      fi
-    fi
-  else
-    OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-    export OPENDS_JAVA_BIN
-  fi
+  exit ${RETURN_CODE}
 fi
 
-
-# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
-# system environment variables for security and compatibility reasons.
-PATH=/bin:/usr/bin
-LD_LIBRARY_PATH=
-LD_LIBRARY_PATH_32=
-LD_LIBRARY_PATH_64=
-LD_PRELOAD=
-LD_PRELOAD_32=
-LD_PRELOAD_64=
-export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
-       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
-
-
-# Configure the appropriate CLASSPATH.
-CLASSPATH=${INSTANCE_ROOT}/classes
-for JAR in ${INSTANCE_ROOT}/lib/*.jar
-do
-  CLASSPATH=${CLASSPATH}:${JAR}
-done
-export CLASSPATH
-
-
-# Determine whether the detected Java environment is acceptable for use.
-if test -z "${JAVA_ARGS}"
-then
-  "${OPENDS_JAVA_BIN}" -client org.opends.server.tools.InstallDS -t 2> /dev/null
-  if test ${?} -eq 0
-  then
-    JAVA_ARGS="-client"
-  else
-    "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
-    if test ${?} -ne 0
-    then
-      echo "ERROR:  The detected Java version could not be used.  Please set "
-      echo "        OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-      exit 1
-    fi
-  fi
-else
-  "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
-  if test ${?} -ne 0
-  then
-    echo "ERROR:  The detected Java version could not be used.  Please set "
-    echo "        OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-    exit 1
-  fi
-fi
-
-
 # Launch the setup process.
-"${OPENDS_JAVA_BIN}" -Dorg.opends.server.scriptName=setup org.opends.quicksetup.installer.SetupLauncher "${@}"
+"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} org.opends.quicksetup.installer.SetupLauncher "${@}"
 
 # return part
 RETURN_CODE=$?
diff --git a/opends/resource/setup.bat b/opends/resource/setup.bat
index b9d6e2a..5f97e52 100644
--- a/opends/resource/setup.bat
+++ b/opends/resource/setup.bat
@@ -39,39 +39,15 @@
 
 set INSTANCE_ROOT=%DIR_HOME%
 
-:checkOpenDSJavaBin
-if "%OPENDS_JAVA_BIN%" == "" goto checkOpenDSJavaHome
-goto setClassPath
+set SCRIPT_NAME=setup
 
-:checkOpenDSJavaHome
-if "%OPENDS_JAVA_HOME%" == "" goto checkOpenDSJavaHomeFile
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkOpenDSJavaHomeFile
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
+rem Set environment variables and test java
+set SCRIPT_UTIL_CMD=set-full-environment-and-test-java
+call "%INSTANCE_ROOT%\lib\_script-util.bat"
+if NOT %errorlevel% == 0 exit /B %errorlevel%
 
-:checkOpenDSJavaHomeFile
-if not exist "%DIR_HOME%\lib\set-java-home.bat" goto checkJavaBin
-call "%DIR_HOME%\lib\set-java-home.bat"
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkJavaBin
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkJavaBin
-if "%JAVA_BIN%" == "" goto checkJavaHome
-set OPENDS_JAVA_BIN=%JAVA_BIN%
-goto setClassPath
-
-:checkJavaHome
-if "%JAVA_HOME%" == "" goto noJavaHome
-if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
-set OPENDS_JAVA_BIN=%JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:noJavaHome
-echo Error: OPENDS_JAVA_HOME environment variable is not set.
-echo        Please set it to a valid Java 5 (or later) installation.
-pause
-goto end
+if "%~1" == "" goto callLaunch
+goto callJava
 
 :invalidPath
 echo Error: The current path contains a %% character.  OpenDS cannot
@@ -79,31 +55,12 @@
 pause
 goto end
 
-:noValidJavaHome
-echo ERROR:  The detected Java version could not be used.  Please set 
-echo         OPENDS_JAVA_HOME to to a valid Java 5 (or later) installation.
-pause
-goto end
-
-:setClassPath
-FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\lib\setcp.bat" %%x
-set CLASSPATH=%DIR_HOME%\classes;%CLASSPATH%
-
-set PATH=%SystemRoot%
-
-rem Test that the provided JDK is 1.5 compatible.
-"%OPENDS_JAVA_BIN%" org.opends.server.tools.InstallDS -t > NUL 2>&1
-if not %errorlevel% == 0 goto noValidJavaHome
-
-if "%~1" == "" goto callLaunch
-goto callJava
-
 :callLaunch
-"%DIR_HOME%\lib\winlauncher.exe" launch "%OPENDS_JAVA_BIN%" %JAVA_ARGS% org.opends.quicksetup.installer.SetupLauncher
+"%DIR_HOME%\lib\winlauncher.exe" launch "%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG% org.opends.quicksetup.installer.SetupLauncher
 goto end
 
 :callJava
-"%OPENDS_JAVA_BIN%" %JAVA_ARGS% org.opends.quicksetup.installer.SetupLauncher %*
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG% org.opends.quicksetup.installer.SetupLauncher %*
 
 rem return part
 if %errorlevel% == 50 goto version
@@ -114,4 +71,3 @@
 exit /B 0
 
 :end
-
diff --git a/opends/resource/uninstall b/opends/resource/uninstall
index 44e6abc..40e701c 100644
--- a/opends/resource/uninstall
+++ b/opends/resource/uninstall
@@ -28,19 +28,6 @@
 
 # This script may be used to uninstall the server.
 
-# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
-# system environment variables for security and compatibility reasons.
-PATH=/bin:/usr/bin
-LD_LIBRARY_PATH=
-LD_LIBRARY_PATH_32=
-LD_LIBRARY_PATH_64=
-LD_PRELOAD=
-LD_PRELOAD_32=
-LD_PRELOAD_64=
-export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
-       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
-
-
 # Capture the current working directory so that we can change to it later.
 # Then capture the location of this script and the Directory Server instance
 # root so that we can use them to create appropriate paths.
@@ -49,88 +36,26 @@
 cd `dirname "${0}"`
 SCRIPT_DIR=`pwd`
 
+SCRIPT_NAME=uninstall
+export SCRIPT_NAME
+
 INSTANCE_ROOT=${SCRIPT_DIR}
 export INSTANCE_ROOT
 
 cd "${WORKING_DIR}"
 
-# See if the environment variables are set.  If not, then see if there is a java
-# executable in the path and try to figure it out.
-if test -z "${OPENDS_JAVA_BIN}"
+# Set environment variables
+SCRIPT_UTIL_CMD=set-full-environment-and-test-java
+export SCRIPT_UTIL_CMD
+.  "${INSTANCE_ROOT}/lib/_script-util.sh"
+RETURN_CODE=$?
+if test ${RETURN_CODE} -ne 0
 then
-  if test -z "${OPENDS_JAVA_HOME}"
-  then
-    if test -f "${INSTANCE_ROOT}/lib/set-java-home"
-    then
-      . "${INSTANCE_ROOT}/lib/set-java-home"
-      OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-      export OPENDS_JAVA_BIN
-    else
-      if test -z "${JAVA_BIN}"
-      then
-        if test -z "${JAVA_HOME}"
-        then
-          OPENDS_JAVA_BIN=`which java 2> /dev/null`
-          if test ${?} -eq 0
-          then
-            export OPENDS_JAVA_BIN
-          else
-            echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-            exit 1
-          fi
-        else
-          OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
-          export OPENDS_JAVA_BIN
-        fi
-      else
-        OPENDS_JAVA_BIN="${JAVA_BIN}"
-        export OPENDS_JAVA_BIN
-      fi
-    fi
-  else
-    OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-    export OPENDS_JAVA_BIN
-  fi
-fi
-
-
-# Configure the appropriate CLASSPATH.
-CLASSPATH=${INSTANCE_ROOT}/classes
-for JAR in ${INSTANCE_ROOT}/lib/*.jar
-do
-  CLASSPATH=${CLASSPATH}:${JAR}
-done
-export CLASSPATH
-
-
-# Determine whether the detected Java environment is acceptable for use.
-if test -z "${JAVA_ARGS}"
-then
-  "${OPENDS_JAVA_BIN}" -client org.opends.server.tools.InstallDS -t 2> /dev/null
-  if test ${?} -eq 0
-  then
-    JAVA_ARGS="-client"
-  else
-    "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
-    if test ${?} -ne 0
-    then
-      echo "ERROR:  The detected Java version could not be used.  Please set "
-      echo "        OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-      exit 1
-    fi
-  fi
-else
-  "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
-  if test ${?} -ne 0
-  then
-    echo "ERROR:  The detected Java version could not be used.  Please set "
-    echo "        OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-    exit 1
-  fi
+  exit ${RETURN_CODE}
 fi
 
 # Launch the uninstall process.
-"${OPENDS_JAVA_BIN}" -Dorg.opends.server.scriptName=uninstall org.opends.guitools.uninstaller.UninstallLauncher "${@}"
+"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} org.opends.guitools.uninstaller.UninstallLauncher "${@}"
 
 # return part
 RETURN_CODE=$?
diff --git a/opends/resource/uninstall.bat b/opends/resource/uninstall.bat
index 7e55c54..71604cc 100644
--- a/opends/resource/uninstall.bat
+++ b/opends/resource/uninstall.bat
@@ -30,66 +30,25 @@
 
 set INSTANCE_ROOT=%DIR_HOME%
 
-:checkOpenDSJavaBin
-if "%OPENDS_JAVA_BIN%" == "" goto checkOpenDSJavaHome
-goto setClassPath
+set SCRIPT_NAME=uninstall
 
-:checkOpenDSJavaHome
-if "%OPENDS_JAVA_HOME%" == "" goto checkOpenDSJavaHomeFile
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkOpenDSJavaHomeFile
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkOpenDSJavaHomeFile
-if not exist "%DIR_HOME%\lib\set-java-home.bat" goto checkJavaBin
-call "%DIR_HOME%\lib\set-java-home.bat"
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkJavaBin
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:checkJavaBin
-if "%JAVA_BIN%" == "" goto checkJavaHome
-set OPENDS_JAVA_BIN=%JAVA_BIN%
-goto setClassPath
-
-:checkJavaHome
-if "%JAVA_HOME%" == "" goto noJavaHome
-if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
-set OPENDS_JAVA_BIN=%JAVA_HOME%\bin\java.exe
-goto setClassPath
-
-:noJavaHome
-echo Error: OPENDS_JAVA_HOME environment variable is not set.
-echo        Please set it to a valid Java 5 (or later) installation.
-pause
-goto end
-
-:noValidJavaHome
-echo ERROR:  The detected Java version could not be used.  Please set 
-echo         OPENDS_JAVA_HOME to to a valid Java 5 (or later) installation.
-pause
-goto end
-
-:setClassPath
-FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\lib\setcp.bat" %%x
-set CLASSPATH=%DIR_HOME%\classes;%CLASSPATH%
-
-set PATH=%SystemRoot%
-
-rem Test that the provided JDK is 1.5 compatible.
-"%OPENDS_JAVA_BIN%" org.opends.server.tools.InstallDS -t > NUL 2>&1
-if not %errorlevel% == 0 goto noValidJavaHome
+rem Set environment variables
+set SCRIPT_UTIL_CMD=set-full-environment-and-test-java
+call "%INSTANCE_ROOT%\lib\_script-util.bat"
+if NOT %errorlevel% == 0 exit /B %errorlevel%
 
 if "%~1" == "" goto callLaunch
 goto callJava
 
 :callLaunch
-"%DIR_HOME%\lib\winlauncher.exe" launch "%OPENDS_JAVA_BIN%" %JAVA_ARGS% org.opends.guitools.uninstaller.UninstallLauncher
+if exist "%DIR_HOME%\lib\set-java-args.bat" DO call "%DIR_HOME%\lib\set-java-args.bat"
+"%DIR_HOME%\lib\winlauncher.exe" launch "%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG% org.opends.guitools.uninstaller.UninstallLauncher
 goto end
 
 :callJava
+if exist "%DIR_HOME%\lib\set-java-args.bat" DO call "%DIR_HOME%\lib\set-java-args.bat"
 set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=uninstall"
-"%OPENDS_JAVA_BIN%" %JAVA_ARGS% org.opends.guitools.uninstaller.UninstallLauncher %*
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG% org.opends.guitools.uninstaller.UninstallLauncher %*
 
 rem return part
 if %errorlevel% == 50 goto version
diff --git a/opends/resource/upgrade b/opends/resource/upgrade
index fc3333c..c615a19 100644
--- a/opends/resource/upgrade
+++ b/opends/resource/upgrade
@@ -25,19 +25,6 @@
 #
 #      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 
-# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
-# system environment variables for security and compatibility reasons.
-PATH=/bin:/usr/bin
-LD_LIBRARY_PATH=
-LD_LIBRARY_PATH_32=
-LD_LIBRARY_PATH_64=
-LD_PRELOAD=
-LD_PRELOAD_32=
-LD_PRELOAD_64=
-export PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
-       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
-
-
 # Capture the current working directory so that we can change to it later.
 # Then capture the location of this script and the Directory Server instance
 # root so that we can use them to create appropriate paths.
@@ -49,47 +36,30 @@
 INSTANCE_ROOT=${SCRIPT_DIR}
 export INSTANCE_ROOT
 
+SCRIPT_NAME=upgrade
+export SCRIPT_NAME
+
 cd "${WORKING_DIR}"
 
-# See if the environment variables are set.  If not, then see if there is a java
-# executable in the path and try to figure it out.
-if test -z "${OPENDS_JAVA_BIN}"
+# Set java home
+SCRIPT_UTIL_CMD=set-java-home-and-args
+export SCRIPT_UTIL_CMD
+.  "${INSTANCE_ROOT}/lib/_script-util.sh"
+RETURN_CODE=$?
+if test ${RETURN_CODE} -ne 0
 then
-  if test -z "${OPENDS_JAVA_HOME}"
-  then
-    if test -f "${INSTANCE_ROOT}/lib/set-java-home"
-    then
-      . "${INSTANCE_ROOT}/lib/set-java-home"
-      OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-      export OPENDS_JAVA_BIN
-    else
-      if test -z "${JAVA_BIN}"
-      then
-        if test -z "${JAVA_HOME}"
-        then
-          OPENDS_JAVA_BIN=`which java 2> /dev/null`
-          if test ${?} -eq 0
-          then
-            export OPENDS_JAVA_BIN
-          else
-            echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-            exit 1
-          fi
-        else
-          OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
-          export OPENDS_JAVA_BIN
-        fi
-      else
-        OPENDS_JAVA_BIN="${JAVA_BIN}"
-        export OPENDS_JAVA_BIN
-      fi
-    fi
-  else
-    OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
-    export OPENDS_JAVA_BIN
-  fi
+  exit ${RETURN_CODE}
 fi
 
+# Set environment variables
+SCRIPT_UTIL_CMD=set-environment-vars
+export SCRIPT_UTIL_CMD
+.  "${INSTANCE_ROOT}/lib/_script-util.sh"
+RETURN_CODE=$?
+if test ${RETURN_CODE} -ne 0
+then
+  exit ${RETURN_CODE}
+fi
 
 # Configure the appropriate CLASSPATH to test.
 for JAR in ${INSTANCE_ROOT}/tmp/upgrade/lib/*.jar
@@ -103,30 +73,14 @@
 done
 export CLASSPATH
 
-# Determine whether the detected Java environment is acceptable for use.
-if test -z "${JAVA_ARGS}"
+# Test the java installation
+SCRIPT_UTIL_CMD=test-java
+export SCRIPT_UTIL_CMD
+.  "${INSTANCE_ROOT}/lib/_script-util.sh"
+RETURN_CODE=$?
+if test ${RETURN_CODE} -ne 0
 then
-  "${OPENDS_JAVA_BIN}" -client org.opends.server.tools.InstallDS -t 2> /dev/null
-  if test ${?} -eq 0
-  then
-    JAVA_ARGS="-client"
-  else
-    "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
-    if test ${?} -ne 0
-    then
-      echo "ERROR:  The detected Java version could not be used.  Please set "
-      echo "        OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
-      exit 1
-    fi
-  fi
-else
-  "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
-  if test ${?} -ne 0
-  then
-    echo "ERROR:  The detected Java version could not be used.  Please set "
-    echo "        OPENDS_JAVA_HOME to the root of a Java 5.0 installation."
-    exit 1
-  fi
+  exit ${RETURN_CODE}
 fi
 
 if [ -r "${INSTANCE_ROOT}/tmp/upgrade" ]
@@ -151,7 +105,7 @@
 # operation is a reversion.  An exit code of 50 means that the usage
 # statement was printed and there is nothing else to do
 
-"${OPENDS_JAVA_BIN}" org.opends.quicksetup.upgrader.BuildExtractor "${@}"
+"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} org.opends.quicksetup.upgrader.BuildExtractor "${@}"
 RETURN_CODE=$?
 if test ${RETURN_CODE} -eq 99
 then
@@ -164,7 +118,7 @@
     CLASSPATH=${JAR}:${CLASSPATH}
   done
   # Launch the upgrade process.
-  "${OPENDS_JAVA_BIN}" org.opends.quicksetup.upgrader.UpgradeLauncher "${@}"
+  "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} org.opends.quicksetup.upgrader.UpgradeLauncher "${@}"
 elif test ${RETURN_CODE} -eq 98
 then
   # Copy jars to a temporary place from which to run the reverter
@@ -182,7 +136,7 @@
       CLASSPATH=${JAR}:${CLASSPATH}
     done
     # Launch the upgrade process.
-    "${OPENDS_JAVA_BIN}" org.opends.quicksetup.upgrader.ReversionLauncher "${@}"
+    "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} org.opends.quicksetup.upgrader.ReversionLauncher "${@}"
   fi
 elif test ${RETURN_CODE} -eq 50
 then
diff --git a/opends/resource/upgrade.bat b/opends/resource/upgrade.bat
index a427698..56560be 100644
--- a/opends/resource/upgrade.bat
+++ b/opends/resource/upgrade.bat
@@ -40,58 +40,19 @@
 echo to 'upgrade.bat' before continuing.
 goto end
 
-:checkOpenDSJavaBin
-if "%OPENDS_JAVA_BIN%" == "" goto checkOpenDSJavaHome
-goto callExtractor
+set SCRIPT_NAME=upgrade
 
-:checkOpenDSJavaHome
-if "%OPENDS_JAVA_HOME%" == "" goto checkOpenDSJavaHomeFile
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkOpenDSJavaHomeFile
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto callExtractor
-
-:checkOpenDSJavaHomeFile
-if not exist "%DIR_HOME%\lib\set-java-home.bat" goto checkJavaBin
-call "%DIR_HOME%\lib\set-java-home.bat"
-if not exist "%OPENDS_JAVA_HOME%\bin\java.exe" goto checkJavaBin
-set OPENDS_JAVA_BIN=%OPENDS_JAVA_HOME%\bin\java.exe
-goto callExtractor
-
-:checkJavaBin
-if "%JAVA_BIN%" == "" goto checkJavaHome
-set OPENDS_JAVA_BIN=%JAVA_BIN%
-goto callExtractor
-
-:checkJavaHome
-if "%JAVA_HOME%" == "" goto noJavaHome
-if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
-set OPENDS_JAVA_BIN=%JAVA_HOME%\bin\java.exe
-goto callExtractor
-
-:noJavaHome
-echo Error: OPENDS_JAVA_HOME environment variable is not set.
-echo        Please set it to a valid Java 5 (or later) installation.
-pause
-goto end
-
-:noValidJavaHome
-echo ERROR:  The detected Java version could not be used.  Please set 
-echo         OPENDS_JAVA_HOME to to a valid Java 5 (or later) installation.
-pause
-goto end
-
-set PATH=%SystemRoot%
-
-rem Test that the provided JDK is 1.5 compatible.
-"%OPENDS_JAVA_BIN%" org.opends.server.tools.InstallDS -t > NUL 2>&1
-if not %errorlevel% == 0 goto noValidJavaHome
+rem Set environment variables and test java
+set SCRIPT_UTIL_CMD=set-full-environment-and-test-java
+call "%INSTANCE_ROOT%\lib\_script-util.bat"
+if NOT %errorlevel% == 0 exit /B %errorlevel%
 
 :callExtractor
 if EXIST "%INSTANCE_ROOT%\tmp\upgrade" rd "%INSTANCE_ROOT%\tmp\upgrade" /s /q
 set CLASSPATH=""
 FOR %%x in ("%INSTANCE_ROOT%\lib\*.jar") DO call "%INSTANCE_ROOT%\lib\setcp.bat" %%x
 set CLASSPATH=%DIR_HOME%\classes;%CLASSPATH%
-"%OPENDS_JAVA_BIN%" org.opends.quicksetup.upgrader.BuildExtractor %*
+"%OPENDS_JAVA_BIN%" %SCRIPT_NAME_ARG% org.opends.quicksetup.upgrader.BuildExtractor %*
 if %errorlevel% == 99 goto upgrader
 if %errorlevel% == 98 goto reverter
 if %errorlevel% == 50 goto version
@@ -101,7 +62,7 @@
 :upgrader
 set CLASSPATH=""
 FOR %%x in ("%INSTANCE_ROOT%\tmp\upgrade\lib\*.jar") DO call "%INSTANCE_ROOT%\lib\setcp.bat" %%x
-"%OPENDS_JAVA_BIN%" org.opends.quicksetup.upgrader.UpgradeLauncher %*
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG%  org.opends.quicksetup.upgrader.UpgradeLauncher %*
 goto end
 
 :reverter
@@ -109,7 +70,7 @@
 xcopy "%INSTANCE_ROOT%\lib\*.*" "%INSTANCE_ROOT%\tmp\revert\lib\" /E /Q /Y
 set CLASSPATH=""
 FOR %%x in ("%INSTANCE_ROOT%\tmp\revert\lib\*.jar") DO call "%INSTANCE_ROOT%\lib\setcp.bat" %%x
-"%OPENDS_JAVA_BIN%" org.opends.quicksetup.upgrader.ReversionLauncher %*
+"%OPENDS_JAVA_BIN%" %OPENDS_JAVA_ARGS% %SCRIPT_NAME_ARG%  org.opends.quicksetup.upgrader.ReversionLauncher %*
 goto end
 
 :version
diff --git a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
index 499742d..398a79f 100644
--- a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
+++ b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
@@ -2822,18 +2822,21 @@
       println(msg);
     }
 
-    long time1 = Utils.getServerClock(ctx1);
-    long time2 = Utils.getServerClock(ctx2);
-    if ((time1 != -1) && (time2 != -1))
+    if (returnValue == SUCCESSFUL)
     {
-      if (Math.abs(time1 - time2) >
-      (Installer.WARNING_CLOCK_DIFFERENCE_THRESOLD_MINUTES * 60 * 1000))
+      long time1 = Utils.getServerClock(ctx1);
+      long time2 = Utils.getServerClock(ctx2);
+      if ((time1 != -1) && (time2 != -1))
       {
-        println(INFO_WARNING_SERVERS_CLOCK_DIFFERENCE.get(
-            ConnectionUtils.getHostPort(ctx1),
-            ConnectionUtils.getHostPort(ctx2),
-            String.valueOf(
-                Installer.WARNING_CLOCK_DIFFERENCE_THRESOLD_MINUTES)));
+        if (Math.abs(time1 - time2) >
+        (Installer.WARNING_CLOCK_DIFFERENCE_THRESOLD_MINUTES * 60 * 1000))
+        {
+          println(INFO_WARNING_SERVERS_CLOCK_DIFFERENCE.get(
+              ConnectionUtils.getHostPort(ctx1),
+              ConnectionUtils.getHostPort(ctx2),
+              String.valueOf(
+                  Installer.WARNING_CLOCK_DIFFERENCE_THRESOLD_MINUTES)));
+        }
       }
     }
 
diff --git a/opends/src/messages/messages/quicksetup.properties b/opends/src/messages/messages/quicksetup.properties
index 4d4d17f..e25d0ea 100644
--- a/opends/src/messages/messages/quicksetup.properties
+++ b/opends/src/messages/messages/quicksetup.properties
@@ -1218,3 +1218,5 @@
 INFO_NEW_UPGRADE_SCRIPT_AVAILABLE=A new version of '%s' has been made \
   available.  After this operation you should delete this script and rename \
   '%s' to '%1$s'.
+MILD_ERR_ERROR_CREATING_JAVA_HOME_SCRIPTS=Error updating scripts with java \
+ properties.  Error code: %d
diff --git a/opends/src/messages/messages/tools.properties b/opends/src/messages/messages/tools.properties
index 35c5456..5363148 100644
--- a/opends/src/messages/messages/tools.properties
+++ b/opends/src/messages/messages/tools.properties
@@ -2193,3 +2193,31 @@
 INFO_INSTALLDS_PROMPT_SKIPPED_FILE_1484=Write skipped entries to file:
 SEVERE_ERR_INSTALLDS_TOO_MANY_KEYSTORE_PASSWORD_TRIES_1485=The maximum number \
  of tries to provide the certificate key store PIN is %s.  Install canceled
+INFO_JAVAPROPERTIES_TOOL_DESCRIPTION_1486=Updates the script files to use the \
+ java binary and java arguments specified in the properties file (%s by \
+ default).  To specify the java binary and the java arguments that must be \
+ used to run the different command-lines (or the server in the case of the %s \
+ command-line) you must edit the properties file
+INFO_JAVAPROPERTIES_DESCRIPTION_SILENT_1487=Run the tool in quiet mode.  Quiet \
+ mode will not output progress information to standard output
+INFO_JAVAPROPERTIES_DESCRIPTION_PROPERTIES_FILE_1488=The properties file to \
+ be used to generate the scripts.  If this attribute is not specified %s will \
+ be used
+INFO_JAVAPROPERTIES_DESCRIPTION_DESTINATION_FILE_1489=The script file that \
+ will be written.  If not specified %s will be written
+INFO_JAVAPROPERTIES_DESCRIPTION_HELP_1490=Display this usage information
+SEVERE_ERR_JAVAPROPERTIES_WITH_PROPERTIES_FILE_1491=The file properties "%s" \
+ cannot be read.  Check that it exists and that you have read rights to it
+SEVERE_ERR_JAVAPROPERTIES_WITH_DESTINATION_FILE_1492=The destination file "%s" \
+ cannot be written.  Check that you have right reads to it
+SEVERE_ERR_JAVAPROPERTIES_WRITING_DESTINATION_FILE_1493=The destination file \
+ "%s" cannot be written.  Check that you have right reads to it
+INFO_JAVAPROPERTIES_SUCCESSFUL_NON_DEFAULT_1494=The script file %s was \
+ successfully created.  For the command-lines to use the java properties \
+ specified on %s you must copy the created script file to %s
+INFO_JAVAPROPERTIES_SUCCESSFUL_1495=The script files were successfully \
+ updated.  The OpenDS command-line utilities will use the java properties \
+ specified on the properties file %s
+INFO_DESCRIPTION_TEST_IF_OFFLINE_1496=When this is set test if the command \
+ must be run in offline or online mode, returning the appropriate error code
+ 
diff --git a/opends/src/quicksetup/org/opends/quicksetup/Installation.java b/opends/src/quicksetup/org/opends/quicksetup/Installation.java
index e882610..9b3e1c1 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/Installation.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/Installation.java
@@ -251,6 +251,33 @@
   public static final String LDIF_DIFF = "ldif-diff";
 
   /**
+   * The default java properties file.
+   */
+  public static final String DEFAULT_JAVA_PROPERTIES_FILE = "java.properties";
+
+  /**
+   * The set java home and arguments properties file for Windows.
+   */
+  public static final String SET_JAVA_PROPERTIES_FILE_WINDOWS =
+    "set-java-home.bat";
+
+  /**
+   * script utils file for UNIX systems.
+   */
+  public static final String SCRIPT_UTIL_FILE_UNIX = "_script-util.sh";
+
+  /**
+   * script utils file for Windows.
+   */
+  public static final String SCRIPT_UTIL_FILE_WINDOWS = "_script-util.bat";
+
+  /**
+   * The set java home and arguments properties file for UNIX systems.
+   */
+  public static final String SET_JAVA_PROPERTIES_FILE_UNIX =
+    "set-java-home";
+
+  /**
    * Directories required to be present for this installation
    * to be considered valid.
    */
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
index 38a226d..428caec 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -1784,7 +1784,8 @@
     {
       // This isn't likely to happen, and it's not a serious problem even if
       // it does.
-      SetupUtils.writeSetOpenDSJavaHome(getInstallationPath(), false);
+      InstallerHelper helper = new InstallerHelper();
+      helper.writeSetOpenDSJavaHome(getInstallationPath());
     } catch (Exception e) {
       LOG.log(Level.WARNING, "Error writing OpenDS Java Home file: "+e, e);
     }
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java b/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java
index 83a2e5d..64e1842 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java
@@ -27,20 +27,32 @@
 
 package org.opends.quicksetup.installer;
 
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Random;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.naming.ldap.InitialLdapContext;
 
 import org.opends.quicksetup.ApplicationException;
+import org.opends.quicksetup.Installation;
 import org.opends.quicksetup.ReturnCode;
+import org.opends.quicksetup.util.Utils;
+
 import static org.opends.quicksetup.util.Utils.*;
 import org.opends.server.admin.DefaultBehaviorException;
 import org.opends.server.admin.ManagedObjectNotFoundException;
@@ -57,6 +69,7 @@
 import org.opends.server.tools.ConfigureDS;
 import org.opends.server.tools.ConfigureWindowsService;
 import org.opends.server.tools.ImportLDIF;
+import org.opends.server.tools.JavaPropertiesTool;
 import org.opends.server.types.DN;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.Entry;
@@ -64,6 +77,7 @@
 import org.opends.server.types.LDIFExportConfig;
 import org.opends.server.util.LDIFException;
 import org.opends.server.util.LDIFWriter;
+import org.opends.server.util.SetupUtils;
 import org.opends.server.util.StaticUtils;
 
 /**
@@ -84,6 +98,8 @@
   private static final int MAX_ID_VALUE = Short.MAX_VALUE;
   private static final String DOMAIN_BASE_NAME = "domain ";
 
+  private static final String INITIAL_CLIENT_HEAP_ARG = "-Xms8m";
+
   /**
    * Invokes the method ConfigureDS.configMain with the provided parameters.
    * @param args the arguments to be passed to ConfigureDS.configMain.
@@ -650,6 +666,282 @@
     }
     return domainName;
   }
+
+  /**
+   * Writes the set-java-home file that is used by the scripts to set the
+   * java home and the java arguments.
+   * @param installPath the install path of the server.
+   * @throws IOException if an error occurred writing the file.
+   */
+  public void writeSetOpenDSJavaHome(String installPath) throws IOException
+  {
+    String javaHome = System.getProperty("java.home");
+    if ((javaHome == null) || (javaHome.length() == 0))
+    {
+      javaHome = System.getenv(SetupUtils.OPENDS_JAVA_HOME);
+    }
+
+    String configDir = Utils.getPath(installPath,
+        Installation.CONFIG_PATH_RELATIVE);
+    String propertiesFile = Utils.getPath(
+        configDir, Installation.DEFAULT_JAVA_PROPERTIES_FILE);
+    boolean propertiesFileModified = false;
+    FileInputStream fs = null;
+    try
+    {
+      fs = new FileInputStream(propertiesFile);
+      Properties properties = new Properties();
+      properties.load(fs);
+      propertiesFileModified = properties.keySet().size() > 0;
+    }
+    catch (Throwable t)
+    {
+    }
+    finally
+    {
+      if (fs != null)
+      {
+        try
+        {
+          fs.close();
+        }
+        catch (Throwable t)
+        {
+        }
+      }
+    }
+    BufferedWriter writer = new BufferedWriter(new FileWriter(propertiesFile,
+        true));
+
+    if (!propertiesFileModified)
+    {
+      writer.newLine();
+      writer.write("overwrite-env-java-home=true");
+      writer.newLine();
+      writer.write("overwrite-env-java-args=true");
+      writer.newLine();
+      writer.newLine();
+      writer.write("default.java-home="+javaHome);
+      writer.newLine();
+      writer.newLine();
+      boolean supportsClient = supportsClient(javaHome, installPath);
+      boolean supportsServer = supportsServer(javaHome, installPath);
+
+
+      boolean supportsClientInitialHeap = supportsInitialHeap(javaHome,
+          installPath);
+
+      // Scripts to which we will pass -client argument
+      String[] clientScripts =
+      {
+          "backup.online", "base64", "create-rc-script", "dsconfig",
+          "dsreplication", "dsframework", "export-ldif.online",
+          "import-ldif.online", "ldapcompare", "ldapdelete",
+          "ldapmodify", "ldappasswordmodify", "ldapsearch", "list-backends",
+          "manage-account", "manage-tasks", "restore.online", "stop-ds",
+          "status", "status-panel", "uninstall", "setup"
+      };
+
+      // Scripts to which we will pass -server argument
+      String[] serverScripts =
+      {
+          "backup.offline", "encode-password", "export-ldif.offline",
+          "import-ldif.offline", "ldif-diff", "ldifmodify", "ldifsearch",
+          "make-ldif", "rebuild-index", "restore.offline", "start-ds",
+          "upgrade", "verify-install"
+      };
+
+      if (supportsServer)
+      {
+        for (int i=0; i<serverScripts.length; i++)
+        {
+          writer.newLine();
+          writer.write(serverScripts[i]+".java-args=-server");
+        }
+      }
+
+
+      if (supportsClient || supportsClientInitialHeap)
+      {
+        for (int i=0; i<clientScripts.length; i++)
+        {
+          writer.newLine();
+          String arg = "";
+          if (supportsClient)
+          {
+            arg = "-client";
+          }
+          if (supportsClientInitialHeap)
+          {
+            if (arg.length() > 0)
+            {
+              arg += " ";
+            }
+            arg += INITIAL_CLIENT_HEAP_ARG;
+          }
+          writer.write(clientScripts[i]+".java-args="+arg);
+        }
+      }
+
+      if (supportsClient || supportsServer || supportsClientInitialHeap)
+      {
+        writer.newLine();
+        writer.newLine();
+      }
+
+      writer.close();
+    }
+    String destinationFile;
+    String libDir = Utils.getPath(installPath,
+        Installation.LIBRARIES_PATH_RELATIVE);
+    if (Utils.isWindows())
+    {
+      destinationFile = Utils.getPath(libDir,
+          Installation.SET_JAVA_PROPERTIES_FILE_WINDOWS);
+    }
+    else
+    {
+      destinationFile = Utils.getPath(libDir,
+          Installation.SET_JAVA_PROPERTIES_FILE_UNIX);
+    }
+
+    // Launch the script
+    String[] args =
+    {
+        "--propertiesFile", propertiesFile,
+        "--destinationFile", destinationFile,
+        "--quiet"
+    };
+
+    int returnValue = JavaPropertiesTool.mainCLI(args);
+
+    if ((returnValue !=
+      JavaPropertiesTool.ErrorReturnCode.SUCCESSFUL.getReturnCode()) &&
+      returnValue !=
+        JavaPropertiesTool.ErrorReturnCode.SUCCESSFUL_NOP.getReturnCode())
+    {
+      LOG.log(Level.WARNING, "Error creating java home scripts, error code: "+
+          returnValue);
+      throw new IOException(
+          ERR_ERROR_CREATING_JAVA_HOME_SCRIPTS.get(returnValue).toString());
+    }
+  }
+
+  /**
+   * Tells whether the provided java installation supports the server option
+   * or not.
+   * @param javaHome the java installation path.
+   * @param installPath the install path of the server.
+   * @return <CODE>true</CODE> if the provided java installation supports the
+   * server option and <CODE>false</CODE> otherwise.
+   */
+  private boolean supportsServer(String javaHome, String installPath)
+  {
+    return supportsOption("-server", javaHome, installPath);
+  }
+
+  /**
+   * Tells whether the provided java installation supports the server option
+   * or not.
+   * @param javaHome the java installation path.
+   * @param installPath the install path of the server.
+   * @return <CODE>true</CODE> if the provided java installation supports the
+   * server option and <CODE>false</CODE> otherwise.
+   */
+  private boolean supportsInitialHeap(String javaHome, String installPath)
+  {
+    return supportsOption(INITIAL_CLIENT_HEAP_ARG, javaHome, installPath);
+  }
+
+  /**
+   * Tells whether the provided java installation supports the client option
+   * or not.
+   * @param javaHome the java installation path.
+   * @param installPath the install path of the server.
+   * @return <CODE>true</CODE> if the provided java installation supports the
+   * client option and <CODE>false</CODE> otherwise.
+   */
+  private boolean supportsClient(String javaHome, String installPath)
+  {
+    return supportsOption("-client", javaHome, installPath);
+  }
+
+  /**
+   * Tells whether the provided java installation supports a given option or
+   * not.
+   * @param javaHome the java installation path.
+   * @param option the java option that we want to check.
+   * @param installPath the install path of the server.
+   * @return <CODE>true</CODE> if the provided java installation supports a
+   * given option and <CODE>false</CODE> otherwise.
+   */
+  private boolean supportsOption(String option, String javaHome,
+      String installPath)
+  {
+    boolean supported = false;
+    try
+    {
+      List<String> args = new ArrayList<String>();
+      String script;
+      String libPath = Utils.getPath(installPath,
+          Installation.LIBRARIES_PATH_RELATIVE);
+      if (Utils.isWindows())
+      {
+        script = Utils.getScriptPath(Utils.getPath(libPath,
+            Installation.SCRIPT_UTIL_FILE_WINDOWS));
+      }
+      else
+      {
+        script = Utils.getScriptPath(Utils.getPath(libPath,
+            Installation.SCRIPT_UTIL_FILE_UNIX));
+      }
+      args.add(script);
+      ProcessBuilder pb = new ProcessBuilder(args);
+      Map<String, String> env = pb.environment();
+      env.put(SetupUtils.OPENDS_JAVA_HOME, javaHome);
+      env.put("OPENDS_JAVA_ARGS", option);
+      env.put("SCRIPT_UTIL_CMD", "set-full-environment-and-test-java");
+      env.remove("OPENDS_JAVA_BIN");
+      // In windows by default the scripts ask the user to click on enter when
+      // they fail.  Set this environment variable to avoid it.
+      if (Utils.isWindows())
+      {
+        env.put("DO_NOT_PAUSE", "true");
+      }
+      Process process = pb.start();
+      LOG.log(Level.INFO, "launching "+args);
+      InputStream is = process.getInputStream();
+      BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+      String line;
+      while (null != (line = reader.readLine())) {
+        LOG.log(Level.INFO, "The output: "+line);
+        if (line.indexOf("ERROR:  The detected Java version") != -1)
+        {
+          try
+          {
+            process.destroy();
+            return false;
+          }
+          catch (Throwable t)
+          {
+            return false;
+          }
+          finally
+          {
+          }
+        }
+      }
+      process.waitFor();
+      int returnCode = process.exitValue();
+      LOG.log(Level.INFO, "returnCode: "+returnCode);
+      supported = returnCode == 0;
+    }
+    catch (Throwable t)
+    {
+      LOG.log(Level.WARNING, "Error testing option "+option+" on "+javaHome, t);
+    }
+    return supported;
+  }
 }
 
 /**
diff --git a/opends/src/server/org/opends/server/tools/InstallDS.java b/opends/src/server/org/opends/server/tools/InstallDS.java
index 2c5c2e1..498de27 100644
--- a/opends/src/server/org/opends/server/tools/InstallDS.java
+++ b/opends/src/server/org/opends/server/tools/InstallDS.java
@@ -85,7 +85,7 @@
  *   <LI>Ask the user if they want to start the server when done installing</LI>
  * </UL>
  */
-public class InstallDS  extends ConsoleApplication
+public class InstallDS extends ConsoleApplication
 {
   private PlainTextProgressMessageFormatter formatter =
     new PlainTextProgressMessageFormatter();
@@ -160,7 +160,7 @@
   private InstallDSArgumentParser argParser;
 
   /**
-   * Constructor for the SetupCli object.
+   * Constructor for the InstallDS object.
    *
    * @param out the print stream to use for standard output.
    * @param err the print stream to use for standard error.
@@ -172,7 +172,7 @@
   }
 
   /**
-   * The main method for the setup CLI tool.
+   * The main method for the InstallDS CLI tool.
    *
    * @param args the command-line arguments provided to this program.
    */
@@ -242,7 +242,8 @@
 
     try {
       QuickSetupLog.initLogFileHandler(
-              File.createTempFile(LOG_FILE_PREFIX, LOG_FILE_SUFFIX),
+              QuickSetupLog.isInitialized() ? null :
+                File.createTempFile(LOG_FILE_PREFIX, LOG_FILE_SUFFIX),
               "org.opends.server.tools");
       QuickSetupLog.disableConsoleLogging();
     } catch (Throwable t) {
@@ -262,7 +263,7 @@
    * @param args the command-line arguments provided to this program.
    * @param  initializeServer  Indicates whether to initialize the server.
    *
-   * @return the return code (SUCCESSFUL, USER_DATA_ERROR or BUG.
+   * @return the return code (SUCCESSFUL, USER_DATA_ERROR or BUG).
    */
   public int execute(String[] args, boolean initializeServer)
   {
@@ -294,35 +295,13 @@
       return ErrorReturnCode.ERROR_USER_DATA.getReturnCode();
     }
 
-    // If we are on test only mode, try to see if the contents of the
-    // set-java-home file are valid.  If they are not try to update them, if no
-    // problem occurred while doing this delete the log file that does not
-    // contain any information.  The test only mode is called several times by
-    // the setup script and if we do not remove it we have a lot of empty log
-    // files.
+    // Delete the log file that does not contain any information.  The test only
+    // mode is called several times by the setup script and if we do not remove
+    // it we have a lot of empty log files.
     if (argParser.testOnlyArg.isPresent())
     {
       try
       {
-        String serverRoot = Utils.getInstallPathFromClasspath();
-        String javaHome = SetupUtils.getOpenDSJavaHome(serverRoot);
-        boolean writeJavaHome = false;
-        if (javaHome != null)
-        {
-          File f = new File(javaHome);
-          if (!f.exists())
-          {
-            writeJavaHome = true;
-          }
-        }
-        else
-        {
-          writeJavaHome = true;
-        }
-        if (writeJavaHome)
-        {
-          SetupUtils.writeSetOpenDSJavaHome(serverRoot, true);
-        }
         QuickSetupLog.getLogFile().deleteOnExit();
       }
       catch (Throwable t)
diff --git a/opends/src/server/org/opends/server/tools/JavaPropertiesTool.java b/opends/src/server/org/opends/server/tools/JavaPropertiesTool.java
new file mode 100644
index 0000000..57d4b65
--- /dev/null
+++ b/opends/src/server/org/opends/server/tools/JavaPropertiesTool.java
@@ -0,0 +1,1004 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2007 Sun Microsystems, Inc.
+ */
+
+package org.opends.server.tools;
+
+import static org.opends.messages.ToolMessages.*;
+import static org.opends.server.util.ServerConstants.EOL;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.opends.messages.Message;
+import org.opends.messages.ToolMessages;
+import org.opends.quicksetup.Constants;
+import org.opends.quicksetup.util.Utils;
+import org.opends.server.types.NullOutputStream;
+import org.opends.server.util.args.ArgumentException;
+import org.opends.server.util.cli.ConsoleApplication;
+
+/**
+ * This class is used to update the scripts that are used to launch the command
+ * lines.  We read the contents of a given properties file and we update the
+ * scripts setting the arguments and JVM to be used by the different scripts.
+ *
+ */
+public class JavaPropertiesTool extends ConsoleApplication
+{
+  // The argument parser
+  private JavaPropertiesToolArgumentParser argParser;
+
+  /**
+   * The enumeration containing the different return codes that the command-line
+   * can have.
+   *
+   */
+  public enum ErrorReturnCode
+  {
+    /**
+     * Successful setup.
+     */
+    SUCCESSFUL(0),
+    /**
+     * We did no have an error but the setup was not executed (displayed version
+     * or usage).
+     */
+    SUCCESSFUL_NOP(0),
+    /**
+     * Unexpected error (potential bug).
+     */
+    ERROR_UNEXPECTED(1),
+    /**
+     * Cannot parse arguments or data provided by user is not valid.
+     */
+    ERROR_USER_DATA(2),
+    /**
+     * Error writing to destination file.
+     */
+    ERROR_WRITING_FILE(3);
+
+    private int returnCode;
+    private ErrorReturnCode(int returnCode)
+    {
+      this.returnCode = returnCode;
+    }
+
+    /**
+     * Get the corresponding return code value.
+     *
+     * @return The corresponding return code value.
+     */
+    public int getReturnCode()
+    {
+      return returnCode;
+    }
+  };
+
+  final private static String DEFAULT_JAVA_HOME_PROP_NAME = "default.java-home";
+  final private static String DEFAULT_JAVA_ARGS_PROP_NAME = "default.java-args";
+  final private static String OVERWRITE_ENV_JAVA_HOME_PROP_NAME =
+    "overwrite-env-java-home";
+  final private static String OVERWRITE_ENV_JAVA_ARGS_PROP_NAME =
+    "overwrite-env-java-args";
+
+  /**
+   * Constructor for the JavaPropertiesTool object.
+   *
+   * @param out the print stream to use for standard output.
+   * @param err the print stream to use for standard error.
+   * @param in the input stream to use for standard input.
+   */
+  public JavaPropertiesTool(PrintStream out, PrintStream err, InputStream in)
+  {
+    super(in, out, err);
+  }
+
+  /**
+   * The main method for the java properties tool.
+   *
+   * @param args the command-line arguments provided to this program.
+   */
+
+  public static void main(String[] args)
+  {
+    int retCode = mainCLI(args, System.out, System.err, System.in);
+
+    System.exit(retCode);
+  }
+
+  /**
+   * Parses the provided command-line arguments and uses that information to
+   * run the java properties tool.
+   *
+   * @param args the command-line arguments provided to this program.
+   *
+   * @return The error code.
+   */
+
+  public static int mainCLI(String[] args)
+  {
+    return mainCLI(args, System.out, System.err, System.in);
+  }
+
+  /**
+   * Parses the provided command-line arguments and uses that information to
+   * run the java properties tool.
+   *
+   * @param  args              The command-line arguments provided to this
+   *                           program.
+   * @param  outStream         The output stream to use for standard output, or
+   *                           <CODE>null</CODE> if standard output is not
+   *                           needed.
+   * @param  errStream         The output stream to use for standard error, or
+   *                           <CODE>null</CODE> if standard error is not
+   *                           needed.
+   * @param  inStream          The input stream to use for standard input.
+   * @return The error code.
+   */
+
+  public static int mainCLI(String[] args, OutputStream outStream,
+      OutputStream errStream, InputStream inStream)
+  {
+    PrintStream out;
+    if (outStream == null)
+    {
+      out = NullOutputStream.printStream();
+    }
+    else
+    {
+      out = new PrintStream(outStream);
+    }
+
+    System.setProperty(Constants.CLI_JAVA_PROPERTY, "true");
+
+    PrintStream err;
+    if (errStream == null)
+    {
+      err = NullOutputStream.printStream();
+    }
+    else
+    {
+      err = new PrintStream(errStream);
+    }
+
+    JavaPropertiesTool tool = new JavaPropertiesTool(out, err, inStream);
+
+    return tool.execute(args);
+  }
+
+  /**
+   * Parses the provided command-line arguments and uses that information to
+   * run the java properties tool.
+   *
+   * @param args the command-line arguments provided to this program.
+   *
+   * @return the return code (SUCCESSFUL, USER_DATA_ERROR or BUG).
+   */
+  public int execute(String[] args)
+  {
+    argParser = new JavaPropertiesToolArgumentParser(
+        JavaPropertiesTool.class.getName());
+    try
+    {
+      argParser.initializeArguments();
+    }
+    catch (ArgumentException ae)
+    {
+      Message message =
+        ToolMessages.ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
+      println(message);
+      return ErrorReturnCode.ERROR_UNEXPECTED.getReturnCode();
+    }
+
+    // Validate user provided data
+    try
+    {
+      argParser.parseArguments(args);
+    }
+    catch (ArgumentException ae)
+    {
+      Message message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
+      println(message);
+      println();
+      println(Message.raw(argParser.getUsage()));
+
+      return ErrorReturnCode.ERROR_USER_DATA.getReturnCode();
+    }
+
+    if (argParser.usageOrVersionDisplayed())
+    {
+      return ErrorReturnCode.SUCCESSFUL_NOP.getReturnCode();
+    }
+
+    Properties properties = new Properties();
+    BufferedReader reader = null;
+    String propertiesFile = argParser.propertiesFileArg.getValue();
+    try
+    {
+      reader = new BufferedReader(new FileReader(propertiesFile));
+    }
+    catch (FileNotFoundException fnfe)
+    {
+      println(ERR_JAVAPROPERTIES_WITH_PROPERTIES_FILE.get(propertiesFile));
+      return ErrorReturnCode.ERROR_USER_DATA.getReturnCode();
+    }
+    try
+    {
+      String line;
+      // Parse the file manually since '\' in windows paths can generate issues.
+      while ((line = reader.readLine()) != null)
+      {
+        line = line.trim();
+        if (!line.startsWith("#"))
+        {
+          int index = line.indexOf('=');
+          if (index != -1)
+          {
+            String key = line.substring(0, index);
+            if (key.indexOf(' ') == -1)
+            {
+              if (index < line.length())
+              {
+                String value = line.substring(index+1);
+                properties.setProperty(key, value);
+              }
+              else
+              {
+                properties.setProperty(key, "");
+              }
+            }
+          }
+        }
+      }
+    }
+    catch (IOException ioe)
+    {
+      println(ERR_JAVAPROPERTIES_WITH_PROPERTIES_FILE.get(propertiesFile));
+      return ErrorReturnCode.ERROR_USER_DATA.getReturnCode();
+    }
+
+    String destinationFile = argParser.destinationFileArg.getValue();
+
+    BufferedWriter writer = null;
+    try
+    {
+      writer = new BufferedWriter(new FileWriter(destinationFile));
+    }
+    catch (IOException ioe)
+    {
+      println(ERR_JAVAPROPERTIES_WITH_DESTINATION_FILE.get(destinationFile));
+      return ErrorReturnCode.ERROR_USER_DATA.getReturnCode();
+    }
+
+    Enumeration propertyNames = properties.propertyNames();
+
+    boolean overwriteEnvJavaHome = true;
+    boolean overwriteEnvJavaArgs = true;
+    String defaultJavaHome = null;
+    String defaultJavaArgs = null;
+
+    while (propertyNames.hasMoreElements())
+    {
+      String name = propertyNames.nextElement().toString();
+      String value = properties.getProperty(name);
+
+      if (value != null)
+      {
+        if (name.equalsIgnoreCase(DEFAULT_JAVA_HOME_PROP_NAME))
+        {
+          defaultJavaHome = value;
+        }
+        else if (name.equalsIgnoreCase(DEFAULT_JAVA_ARGS_PROP_NAME))
+        {
+          defaultJavaArgs = value;
+        }
+        else if (name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_HOME_PROP_NAME))
+        {
+          if ("false".equalsIgnoreCase(value))
+          {
+            overwriteEnvJavaHome = false;
+          }
+        }
+        else if (name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_ARGS_PROP_NAME))
+        {
+          if ("false".equalsIgnoreCase(value))
+          {
+            overwriteEnvJavaArgs = false;
+          }
+        }
+      }
+    }
+
+    try
+    {
+      String value;
+      if (Utils.isWindows())
+      {
+        value = getWindowsContents(overwriteEnvJavaHome, overwriteEnvJavaArgs,
+            defaultJavaHome, defaultJavaArgs, properties);
+      }
+      else
+      {
+        value = getUnixContents(overwriteEnvJavaHome, overwriteEnvJavaArgs,
+            defaultJavaHome, defaultJavaArgs, properties);
+      }
+
+      writer.write(value);
+      writer.newLine();
+      writer.close();
+    }
+    catch (IOException ioe)
+    {
+      println(Utils.getThrowableMsg(
+          ERR_JAVAPROPERTIES_WRITING_DESTINATION_FILE.get(destinationFile),
+          ioe));
+      return ErrorReturnCode.ERROR_WRITING_FILE.getReturnCode();
+    }
+
+    // Add some information if we are not in quiet mode about
+    // what is going to happen.
+    File f1 = new File(argParser.destinationFileArg.getValue());
+    File f2 = new File(argParser.destinationFileArg.getDefaultValue());
+    if (f1.equals(f2))
+    {
+      printProgress(INFO_JAVAPROPERTIES_SUCCESSFUL.get(
+          argParser.propertiesFileArg.getValue()));
+    }
+    else
+    {
+      printProgress(INFO_JAVAPROPERTIES_SUCCESSFUL_NON_DEFAULT.get(
+          argParser.destinationFileArg.getValue(),
+          argParser.propertiesFileArg.getValue(),
+          argParser.destinationFileArg.getDefaultValue()));
+    }
+    printlnProgress();
+
+
+    return ErrorReturnCode.SUCCESSFUL.getReturnCode();
+  }
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isQuiet()
+  {
+    return argParser.quietArg.isPresent();
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isInteractive()
+  {
+    return false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public boolean isMenuDrivenMode() {
+    return true;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isScriptFriendly() {
+    return false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isAdvancedMode() {
+    return false;
+  }
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isVerbose() {
+    return true;
+  }
+
+  private String getUnixContents(boolean overwriteJavaHome,
+      boolean overwriteJavaArgs, String defaultJavaHome, String defaultJavaArgs,
+      Properties properties)
+  {
+    StringBuilder buf = new StringBuilder();
+    buf.append("#!/bin/sh"+EOL+EOL);
+
+    if (!overwriteJavaHome)
+    {
+      buf.append(
+          "# See if the environment variables for java home are set"+EOL+
+          "# in the path and try to figure it out."+EOL+
+          "if test ! -f \"${OPENDS_JAVA_BIN}\""+EOL+
+          "then"+EOL+
+          "  if test ! -d \"${OPENDS_JAVA_HOME}\""+EOL);
+    }
+
+    boolean propertiesAdded = false;
+
+    Enumeration propertyNames = properties.propertyNames();
+    int nIfs = 0;
+    while (propertyNames.hasMoreElements())
+    {
+      String name = propertyNames.nextElement().toString();
+      String value = properties.getProperty(name);
+
+      if (value != null)
+      {
+        if (name.equalsIgnoreCase(DEFAULT_JAVA_HOME_PROP_NAME) ||
+            name.equalsIgnoreCase(DEFAULT_JAVA_ARGS_PROP_NAME) ||
+            name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_HOME_PROP_NAME) ||
+            name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_ARGS_PROP_NAME))
+        {
+          // Already handled
+        }
+        else if (name.endsWith(".java-home"))
+        {
+          propertiesAdded = true;
+          String s;
+          if (nIfs > 0)
+          {
+            buf.append(
+                "  elif test \"${SCRIPT_NAME}.java-home\" = \""+name+"\""+EOL);
+            s = "    ";
+          }
+          else if (!overwriteJavaHome)
+          {
+            buf.append(
+                "  then"+EOL+
+                "    if test \"${SCRIPT_NAME}.java-home\" = \""+name+"\""+EOL);
+            s = "      ";
+          }
+          else
+          {
+            buf.append(
+                "if test \"${SCRIPT_NAME}.java-home\" = \""+name+"\""+EOL);
+            s = "";
+          }
+
+          buf.append(
+          s+"then"+EOL+
+          s+"  TEMP=\""+value+"/bin/java\""+EOL+
+          s+"  if test -f ${TEMP}"+EOL+
+          s+"  then"+EOL+
+          s+"    OPENDS_JAVA_BIN=\""+value+"/bin/java\""+EOL+
+          s+"    export OPENDS_JAVA_BIN"+EOL+
+          s+"  fi"+EOL);
+          nIfs++;
+        }
+      }
+    }
+    if (defaultJavaHome != null)
+    {
+      if (propertiesAdded)
+      {
+        String s;
+        if (!overwriteJavaHome)
+        {
+          s = "  ";
+        }
+        else
+        {
+          s = "";
+        }
+        buf.append(
+            s+"else"+EOL+
+            s+"  OPENDS_JAVA_BIN=\""+defaultJavaHome+"/bin/java\""+EOL+
+            s+"  export OPENDS_JAVA_BIN"+EOL);
+      }
+      else
+      {
+        if (!overwriteJavaHome)
+        {
+          buf.append(
+              "  then"+EOL+
+              "    TEMP=\""+defaultJavaHome+"/bin/java\""+EOL+
+              "    if test -f ${TEMP}"+EOL+
+              "    then"+EOL+
+              "      OPENDS_JAVA_BIN=${TEMP}"+EOL+
+              "      export OPENDS_JAVA_BIN"+EOL+
+              "    fi"+EOL);
+        }
+        else
+        {
+          buf.append(
+            "OPENDS_JAVA_BIN=\""+defaultJavaHome+"/bin/java\""+EOL+
+            "export OPENDS_JAVA_BIN"+EOL);
+        }
+      }
+      propertiesAdded = true;
+    }
+
+    if (nIfs > 0)
+    {
+      String s;
+      if (!overwriteJavaHome)
+      {
+        s = "  ";
+      }
+      else
+      {
+        s = "";
+      }
+      buf.append(
+          s+"fi"+EOL);
+    }
+
+
+    if (!overwriteJavaHome)
+    {
+      if (!propertiesAdded)
+      {
+        // No properties added: this is required not to break the script
+        buf.append(
+            "  then"+EOL+
+            "  OPENDS_JAVA_BIN=${OPENDS_JAVA_BIN}"+EOL);
+      }
+      buf.append(
+          "  else"+EOL+
+          "    OPENDS_JAVA_BIN=${OPENDS_JAVA_HOME}/bin/java"+EOL+
+          "    export OPENDS_JAVA_BIN"+EOL+
+          "  fi"+EOL+
+          "fi");
+    }
+    else if (defaultJavaHome == null)
+    {
+      buf.append(
+          EOL+
+          "if test ! -f \"${OPENDS_JAVA_BIN}\""+EOL+
+          "then"+EOL+
+          "  if test ! -d \"${OPENDS_JAVA_HOME}\""+EOL+
+          "  then"+EOL+
+          "    if test ! -f \"${JAVA_BIN}\""+EOL+
+          "    then"+EOL+
+          "      if test ! -d \"${JAVA_HOME}\""+EOL+
+          "      then"+EOL+
+          "        OPENDS_JAVA_BIN=`which java 2> /dev/null`"+EOL+
+          "        if test ${?} -eq 0"+EOL+
+          "        then"+EOL+
+          "          export OPENDS_JAVA_BIN"+EOL+
+          "        else"+EOL+
+          "          echo \"You must specify the path to a valid Java 5.0 or "+
+          "higher version in the\""+EOL+
+          "          echo \"properties file and then run the dsjavaproperties "+
+          "tool. \""+EOL+
+          "          echo \"The procedure to follow is:\""+EOL+
+          "          echo \"You must specify the path to a valid Java 5.0 or "+
+          "higher version.  The \""+EOL+
+          "          echo \"procedure to follow is:"+EOL+
+          "          echo \"1. Delete the file "+
+          "${INSTANCE_ROOT}/lib/set-java-home\""+EOL+
+          "          echo \"2. Set the environment variable OPENDS_JAVA_HOME "+
+          "to the root of a valid \""+EOL+
+          "          echo \"Java 5.0 installation.\""+EOL+
+          "          echo \"If you want to have specificjava  settings for "+
+          "each command line you must\""+EOL+
+          "          echo \"follow the steps 3 and 4\""+EOL+
+          "          echo \"3. Edit the properties file specifying the java "+
+          "binary and the java arguments\""+EOL+
+          "          echo \"for each command line.  The java properties file "+
+          "is located in:\""+EOL+
+          "          echo \"${INSTANCE_ROOT}/config/java.properties.\""+EOL+
+          "          echo \"4. Run the command-line "+
+          "${INSTANCE_ROOT}/bin/dsjavaproperties\""+EOL+
+          "          exit 1"+EOL+
+          "        fi"+EOL+
+          "      else"+EOL+
+          "        OPENDS_JAVA_BIN=\"${JAVA_HOME}/bin/java\""+EOL+
+          "        export OPENDS_JAVA_BIN"+EOL+
+          "      fi"+EOL+
+          "    else"+EOL+
+          "      OPENDS_JAVA_BIN=\"${JAVA_BIN}\""+EOL+
+          "      export OPENDS_JAVA_BIN"+EOL+
+          "    fi"+EOL+
+          "  else"+EOL+
+          "    OPENDS_JAVA_BIN=\"${OPENDS_JAVA_HOME}/bin/java\""+EOL+
+          "    export OPENDS_JAVA_BIN"+EOL+
+          "  fi"+EOL+
+          "fi"+EOL);
+    }
+
+
+    if (!overwriteJavaArgs)
+    {
+      buf.append(
+          EOL+
+          "# See if the environment variables for arguments are set."+EOL+
+          "if test -z \"${OPENDS_JAVA_ARGS}\""+EOL+
+          "  if test -z \"${JAVA_ARGS}\""+EOL);
+    }
+
+    propertiesAdded = false;
+
+    propertyNames = properties.propertyNames();
+    nIfs = 0;
+    while (propertyNames.hasMoreElements())
+    {
+      String name = propertyNames.nextElement().toString();
+      String value = properties.getProperty(name);
+
+      String s = overwriteJavaArgs? "":"    ";
+
+      if (value != null)
+      {
+        if (name.equalsIgnoreCase(DEFAULT_JAVA_HOME_PROP_NAME) ||
+            name.equalsIgnoreCase(DEFAULT_JAVA_ARGS_PROP_NAME) ||
+            name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_HOME_PROP_NAME) ||
+            name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_ARGS_PROP_NAME))
+        {
+          // Already handled
+        }
+        else if (name.endsWith(".java-args"))
+        {
+          propertiesAdded = true;
+          if (nIfs > 0)
+          {
+            buf.append(
+                s+"elif test \"${SCRIPT_NAME}.java-args\" = \""+name+"\""+EOL);
+          }
+          else if (!overwriteJavaArgs)
+          {
+            buf.append(
+                "  then"+EOL+
+                "    if test \"${SCRIPT_NAME}.java-args\" = \""+name+"\""+EOL);
+          }
+          else
+          {
+            buf.append(
+                "if test \"${SCRIPT_NAME}.java-args\" = \""+name+"\""+EOL);
+          }
+          buf.append(
+          s+"then"+EOL+
+          s+"  OPENDS_JAVA_ARGS=\""+value+"\""+EOL+
+          s+"  export OPENDS_JAVA_ARGS"+EOL);
+          nIfs++;
+        }
+      }
+    }
+    if (defaultJavaArgs != null)
+    {
+      String s = overwriteJavaArgs? "":"    ";
+      if (propertiesAdded)
+      {
+        buf.append(
+            s+"else"+EOL+
+            s+"  OPENDS_JAVA_ARGS=\""+defaultJavaArgs+"\""+EOL+
+            s+"  export OPENDS_JAVA_ARGS"+EOL);
+      }
+      else
+      {
+        if (!overwriteJavaArgs)
+        {
+          buf.append(
+              "    then"+EOL+
+              "      OPENDS_JAVA_ARGS=\""+defaultJavaArgs+"\""+EOL+
+              "      export OPENDS_JAVA_ARGS"+EOL);
+        }
+        else
+        {
+          buf.append(
+              EOL+
+              "OPENDS_JAVA_ARGS=\""+defaultJavaArgs+"\""+EOL+
+              "export OPENDS_JAVA_ARGS"+EOL);
+        }
+      }
+      propertiesAdded = true;
+    }
+    if (nIfs > 0)
+    {
+      String s = overwriteJavaArgs? "":"  ";
+      buf.append(s+"fi"+EOL);
+    }
+
+    if (!overwriteJavaArgs)
+    {
+      if (!propertiesAdded)
+      {
+        // No properties added: this is required not to break the script
+        buf.append(
+            "    then"+EOL+
+            "    OPENDS_JAVA_ARGS=${OPENDS_JAVA_ARGS}"+EOL);
+      }
+      buf.append(
+          "  else"+EOL+
+          "    OPENDS_JAVA_ARGS=${JAVA_ARGS}"+EOL+
+          "    export OPENDS_JAVA_ARGS"+EOL+
+          "  fi"+EOL+
+          "fi"+EOL);
+    }
+
+    return buf.toString();
+  }
+
+  private String getWindowsContents(boolean overwriteJavaHome,
+      boolean overwriteJavaArgs, String defaultJavaHome, String defaultJavaArgs,
+      Properties properties)
+  {
+    StringBuilder buf = new StringBuilder();
+
+    String javaHomeLabel1;
+    String javaArgsLabel1;
+    String javaHomeLabel2;
+    String javaArgsLabel2;
+
+    final String CHECK_ENV_JAVA_HOME = "checkEnvJavaHome";
+    final String CHECK_ENV_JAVA_ARGS = "checkEnvJavaArgs";
+    final String CHECK_JAVA_HOME = "checkJavaHome";
+    final String CHECK_JAVA_ARGS = "checkJavaArgs";
+    final String CHECK_DEFAULT_JAVA_HOME = "checkDefaultJavaHome";
+    final String CHECK_DEFAULT_JAVA_ARGS = "checkDefaultJavaArgs";
+
+    if (!overwriteJavaHome)
+    {
+      javaHomeLabel1 = CHECK_ENV_JAVA_HOME;
+      javaHomeLabel2 = CHECK_JAVA_HOME;
+    }
+    else
+    {
+      javaHomeLabel1 = CHECK_JAVA_HOME;
+      javaHomeLabel2 = CHECK_ENV_JAVA_HOME;
+    }
+
+    if (!overwriteJavaArgs)
+    {
+      javaArgsLabel1 = CHECK_ENV_JAVA_ARGS;
+      javaArgsLabel2 = CHECK_JAVA_ARGS;
+    }
+    else
+    {
+      javaArgsLabel1 = CHECK_JAVA_ARGS;
+      javaArgsLabel2 = CHECK_ENV_JAVA_ARGS;
+    }
+
+    buf.append("goto "+javaHomeLabel1+EOL+EOL);
+
+    buf.append(
+        ":"+CHECK_ENV_JAVA_HOME+EOL+
+        "if \"%OPENDS_JAVA_BIN%\" == \"\" goto checkOpendsJavaHome"+EOL+
+        "if not exist \"%OPENDS_JAVA_BIN%\" goto checkOpendsJavaHome"+EOL+
+        "goto "+javaArgsLabel1+EOL+EOL+
+        ":checkOpendsJavaHome"+EOL);
+
+    if (javaHomeLabel1 == CHECK_ENV_JAVA_HOME)
+    {
+      buf.append(
+          "if \"%OPENDS_JAVA_HOME%\" == \"\" goto "+javaHomeLabel2+EOL+
+          "set TEMP=%OPENDS_JAVA_HOME%\\bin\\java.exe"+EOL+
+          "if not exist \"%TEMP%\" goto "+javaHomeLabel2+EOL+
+          "set OPENDS_JAVA_BIN=%TEMP%"+EOL+
+          "goto "+javaArgsLabel1+EOL+EOL
+      );
+    }
+    else
+    {
+      buf.append(
+          "if \"%OPENDS_JAVA_HOME%\" == \"\" goto "+javaArgsLabel1+EOL+
+          "set TEMP=%OPENDS_JAVA_HOME%\\bin\\java.exe"+EOL+
+          "if not exist \"%TEMP%\" goto "+javaArgsLabel1+EOL+
+          "set OPENDS_JAVA_BIN=%TEMP%"+EOL+
+          "goto "+javaArgsLabel1+EOL+EOL
+      );
+    }
+
+    if (defaultJavaHome != null)
+    {
+      if (javaHomeLabel1 == CHECK_ENV_JAVA_HOME)
+      {
+        buf.append(
+            ":"+CHECK_DEFAULT_JAVA_HOME+EOL+
+            "set TEMP="+defaultJavaHome+"\\bin\\java.exe"+EOL+
+            "if not exist \"%TEMP%\" goto "+javaArgsLabel1+EOL+
+            "set OPENDS_JAVA_BIN=%TEMP%"+EOL+
+            "goto "+javaArgsLabel1+EOL+EOL
+        );
+      }
+      else
+      {
+        buf.append(
+            ":"+CHECK_DEFAULT_JAVA_HOME+EOL+
+            "set TEMP="+defaultJavaHome+"\\bin\\java.exe"+EOL+
+            "if not exist \"%TEMP%\" goto "+CHECK_ENV_JAVA_HOME+EOL+
+            "set OPENDS_JAVA_BIN=%TEMP%"+EOL+
+            "goto "+javaArgsLabel1+EOL+EOL
+        );
+      }
+    }
+
+    buf.append(
+        ":"+CHECK_JAVA_HOME+EOL);
+    Enumeration propertyNames = properties.propertyNames();
+    while (propertyNames.hasMoreElements())
+    {
+      String name = propertyNames.nextElement().toString();
+      if (name.equalsIgnoreCase(DEFAULT_JAVA_HOME_PROP_NAME) ||
+          name.equalsIgnoreCase(DEFAULT_JAVA_ARGS_PROP_NAME) ||
+          name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_HOME_PROP_NAME) ||
+          name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_ARGS_PROP_NAME))
+      {
+        // Already handled
+      }
+      else if (name.endsWith(".java-home"))
+      {
+        String scriptName = name.substring(0,
+            name.length() - ".java-home".length());
+        buf.append(
+            "if \"%SCRIPT_NAME%.java-home\" == \""+name+"\" goto check"+
+            scriptName+"JavaHome"+EOL);
+      }
+    }
+    if (defaultJavaHome != null)
+    {
+      buf.append("goto "+CHECK_DEFAULT_JAVA_HOME+EOL+EOL);
+    }
+    else if (javaHomeLabel1 != CHECK_ENV_JAVA_HOME)
+    {
+      buf.append("goto "+CHECK_ENV_JAVA_HOME+EOL+EOL);
+    }
+    else
+    {
+      buf.append("goto "+javaArgsLabel1+EOL+EOL);
+    }
+
+    propertyNames = properties.propertyNames();
+    while (propertyNames.hasMoreElements())
+    {
+      String name = propertyNames.nextElement().toString();
+      String value = properties.getProperty(name);
+      if (name.equalsIgnoreCase(DEFAULT_JAVA_HOME_PROP_NAME) ||
+          name.equalsIgnoreCase(DEFAULT_JAVA_ARGS_PROP_NAME) ||
+          name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_HOME_PROP_NAME) ||
+          name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_ARGS_PROP_NAME))
+      {
+        // Already handled
+      }
+      else if (name.endsWith(".java-home"))
+      {
+        String scriptName = name.substring(0,
+            name.length() - ".java-home".length());
+        buf.append(
+            ":check"+scriptName+"JavaHome"+EOL+
+            "set TEMP="+value+"\\bin\\java.exe"+EOL);
+        if (defaultJavaHome != null)
+        {
+          buf.append(
+              "if not exist \"%TEMP%\" goto "+CHECK_DEFAULT_JAVA_HOME+EOL);
+        }
+        else if (javaHomeLabel1 != CHECK_ENV_JAVA_HOME)
+        {
+          buf.append(
+              "if not exist \"%TEMP%\" goto "+CHECK_ENV_JAVA_HOME+EOL);
+        }
+        buf.append(
+            "set OPENDS_JAVA_BIN=%TEMP%"+EOL+
+            "goto "+javaArgsLabel1+EOL+EOL);
+      }
+    }
+
+    buf.append(
+        ":"+CHECK_ENV_JAVA_ARGS+EOL);
+    if (javaArgsLabel1 == CHECK_ENV_JAVA_ARGS)
+    {
+      buf.append(
+          "if \"%OPENDS_JAVA_ARGS%\" == \"\" goto "+javaArgsLabel2+EOL+
+          "goto end"+EOL+EOL);
+    }
+    else
+    {
+      buf.append(
+          "if NOT \"%OPENDS_JAVA_ARGS%\" == \"\" goto end"+EOL+
+          "set OPENDS_JAVA_ARGS=%JAVA_ARGS%"+EOL+
+          "goto end"+EOL+EOL);
+    }
+
+    if (defaultJavaArgs != null)
+    {
+      buf.append(
+          ":"+CHECK_DEFAULT_JAVA_ARGS+EOL+
+          "set OPENDS_JAVA_ARGS="+defaultJavaArgs+EOL+
+          "goto end"+EOL+EOL);
+    }
+
+    buf.append(
+        ":"+CHECK_JAVA_ARGS+EOL);
+    propertyNames = properties.propertyNames();
+    while (propertyNames.hasMoreElements())
+    {
+      String name = propertyNames.nextElement().toString();
+      if (name.equalsIgnoreCase(DEFAULT_JAVA_HOME_PROP_NAME) ||
+          name.equalsIgnoreCase(DEFAULT_JAVA_ARGS_PROP_NAME) ||
+          name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_HOME_PROP_NAME) ||
+          name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_ARGS_PROP_NAME))
+      {
+        // Already handled
+      }
+      else if (name.endsWith(".java-args"))
+      {
+        String scriptName = name.substring(0,
+            name.length() - ".java-args".length());
+        buf.append(
+            "if \"%SCRIPT_NAME%.java-args\" == \""+name+"\" goto check"+
+            scriptName+"JavaArgs"+EOL);
+      }
+    }
+    if (defaultJavaArgs != null)
+    {
+      buf.append("goto "+CHECK_DEFAULT_JAVA_ARGS+EOL+EOL);
+    }
+    else if (javaArgsLabel1 != CHECK_ENV_JAVA_ARGS)
+    {
+      buf.append("goto "+CHECK_ENV_JAVA_ARGS+EOL+EOL);
+    }
+    else
+    {
+      buf.append("goto end"+EOL+EOL);
+    }
+
+    propertyNames = properties.propertyNames();
+    while (propertyNames.hasMoreElements())
+    {
+      String name = propertyNames.nextElement().toString();
+      String value = properties.getProperty(name);
+      if (name.equalsIgnoreCase(DEFAULT_JAVA_HOME_PROP_NAME) ||
+          name.equalsIgnoreCase(DEFAULT_JAVA_ARGS_PROP_NAME) ||
+          name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_HOME_PROP_NAME) ||
+          name.equalsIgnoreCase(OVERWRITE_ENV_JAVA_ARGS_PROP_NAME))
+      {
+        // Already handled
+      }
+      else if (name.endsWith(".java-args"))
+      {
+        String scriptName = name.substring(0,
+            name.length() - ".java-args".length());
+        buf.append(
+            ":check"+scriptName+"JavaArgs"+EOL+
+            "set OPENDS_JAVA_ARGS="+value+EOL+
+            "goto end"+EOL+EOL);
+      }
+    }
+
+    buf.append(":end"+EOL);
+
+    return buf.toString();
+  }
+}
diff --git a/opends/src/server/org/opends/server/tools/JavaPropertiesToolArgumentParser.java b/opends/src/server/org/opends/server/tools/JavaPropertiesToolArgumentParser.java
new file mode 100644
index 0000000..b0e9096
--- /dev/null
+++ b/opends/src/server/org/opends/server/tools/JavaPropertiesToolArgumentParser.java
@@ -0,0 +1,194 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2007 Sun Microsystems, Inc.
+ */
+package org.opends.server.tools;
+
+import static org.opends.messages.ToolMessages.*;
+import static org.opends.server.tools.ToolConstants.*;
+
+import java.io.File;
+import java.util.LinkedHashSet;
+
+import org.opends.messages.Message;
+import org.opends.quicksetup.Constants;
+import org.opends.quicksetup.Installation;
+import org.opends.quicksetup.util.Utils;
+import org.opends.server.util.args.ArgumentException;
+import org.opends.server.util.args.ArgumentParser;
+import org.opends.server.util.args.BooleanArgument;
+import org.opends.server.util.args.StringArgument;
+
+/**
+ * Class used to parse the arguments of the java properties tool command-line.
+ */
+public class JavaPropertiesToolArgumentParser extends ArgumentParser
+{
+  // Usage argument
+  BooleanArgument   showUsageArg;
+  // Quiet argument
+  BooleanArgument   quietArg;
+  // The file containing the properties
+  StringArgument propertiesFileArg;
+  // The file that is generated
+  StringArgument destinationFileArg;
+
+  /**
+   * The default constructor for this class.
+   * @param mainClassName the class name of the main class for the command-line
+   * that is being used.
+   */
+  public JavaPropertiesToolArgumentParser(String mainClassName)
+  {
+    super(mainClassName,
+        INFO_JAVAPROPERTIES_TOOL_DESCRIPTION.get(getDefaultPropertiesValue(),
+        Utils.isWindows() ?
+            Installation.WINDOWS_START_FILE_NAME :
+              Installation.UNIX_START_FILE_NAME),
+        false);
+  }
+
+  /**
+   * Initializes the arguments without parsing them.
+   * @throws ArgumentException if there was an error creating or adding the
+   * arguments.  If this occurs is likely to be a bug.
+   */
+  public void initializeArguments() throws ArgumentException
+  {
+    quietArg = new BooleanArgument(
+        "quiet", OPTION_SHORT_QUIET,
+        OPTION_LONG_QUIET,
+        INFO_JAVAPROPERTIES_DESCRIPTION_SILENT.get());
+    quietArg.setPropertyName(OPTION_LONG_QUIET);
+    addArgument(quietArg);
+
+    propertiesFileArg = new StringArgument("propertiesFile",
+        'p', "propertiesFile", false,
+        false, true, "{path}", getDefaultPropertiesValue(),
+        "propertiesFile",
+        INFO_JAVAPROPERTIES_DESCRIPTION_PROPERTIES_FILE.get(
+            getDefaultPropertiesValue()));
+    addArgument(propertiesFileArg);
+
+    destinationFileArg = new StringArgument("destinationFile",
+        'd', "destinationFile", false,
+        false, true, "{path}", getDefaultDestinationValue(),
+        "destinationFile",
+        INFO_JAVAPROPERTIES_DESCRIPTION_DESTINATION_FILE.get(
+            getDefaultDestinationValue()));
+    addArgument(destinationFileArg);
+
+    showUsageArg = new BooleanArgument("help", OPTION_SHORT_HELP,
+        OPTION_LONG_HELP,
+        INFO_JAVAPROPERTIES_DESCRIPTION_HELP.get());
+    addArgument(showUsageArg);
+    setUsageArgument(showUsageArg);
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override()
+  public void parseArguments(String[] args) throws ArgumentException
+  {
+    LinkedHashSet<Message> errorMessages = new LinkedHashSet<Message>();
+    try
+    {
+      super.parseArguments(args);
+    }
+    catch (ArgumentException ae)
+    {
+      errorMessages.add(ae.getMessageObject());
+    }
+
+    if (!isUsageArgumentPresent() && !isVersionArgumentPresent())
+    {
+      String value = propertiesFileArg.getValue();
+      if (value != null)
+      {
+        File f = new File(value);
+        if (!f.exists() || !f.isFile() || !f.canRead())
+        {
+          errorMessages.add(ERR_JAVAPROPERTIES_WITH_PROPERTIES_FILE.get(value));
+        }
+      }
+      value = destinationFileArg.getValue();
+      if (value != null)
+      {
+        File f = new File(value);
+        if (f.isDirectory() || !Utils.canWrite(value))
+        {
+          errorMessages.add(
+              ERR_JAVAPROPERTIES_WITH_DESTINATION_FILE.get(value));
+        }
+      }
+      if (errorMessages.size() > 0)
+      {
+        Message message = ERR_CANNOT_INITIALIZE_ARGS.get(
+            Utils.getMessageFromCollection(errorMessages,
+                Constants.LINE_SEPARATOR));
+        throw new ArgumentException(message);
+      }
+    }
+  }
+
+  /**
+   * Returns the default destination file by inspecting the class loader.
+   * @return the default destination file retrieved by inspecting the class
+   * loader.
+   */
+  private String getDefaultDestinationValue()
+  {
+    String value;
+    // Use this instead of Installation.getLocal() because making that call
+    // starts a new JVM and the command-line becomes less responsive.
+    String root = Utils.getInstallPathFromClasspath();
+    String libDir = Utils.getPath(root, Installation.LIBRARIES_PATH_RELATIVE);
+    if (Utils.isWindows())
+    {
+      value = Utils.getPath(libDir,
+          Installation.SET_JAVA_PROPERTIES_FILE_WINDOWS);
+    }
+    else
+    {
+      value = Utils.getPath(libDir, Installation.SET_JAVA_PROPERTIES_FILE_UNIX);
+    }
+    return value;
+  }
+
+  /**
+   * Returns the default java properties file by inspecting the class loader.
+   * @return the default java properties file retrieved by inspecting the class
+   * loader.
+   */
+  private static String getDefaultPropertiesValue()
+  {
+    // Use this instead of Installation.getLocal() because making that call
+    // starts a new JVM and the command-line becomes less responsive.
+    String root = Utils.getInstallPathFromClasspath();
+    String configDir = Utils.getPath(root, Installation.CONFIG_PATH_RELATIVE);
+    return Utils.getPath(configDir, Installation.DEFAULT_JAVA_PROPERTIES_FILE);
+  }
+}
\ No newline at end of file
diff --git a/opends/src/server/org/opends/server/tools/tasks/TaskTool.java b/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
index 84c6e64..764503e 100644
--- a/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
+++ b/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
@@ -74,6 +74,9 @@
    */
   public static final String NOW = "0";
 
+  private static final int RUN_OFFLINE = 51;
+  private static final int RUN_ONLINE = 52;
+
   // Number of milliseconds this utility will wait before reloading
   // this task's entry in the directory while it is polling for status
   private static final int SYNCHRONOUS_TASK_POLL_INTERVAL = 1000;
@@ -98,6 +101,10 @@
   // Client for interacting with the task backend
   TaskClient taskClient;
 
+  // Argument used to know whether we must test if we must run in offline
+  // mode.
+  BooleanArgument testIfOfflineArg;
+
   /**
    * Called when this utility should perform its actions locally in this
    * JVM.
@@ -121,8 +128,8 @@
    * @return LDAPConnectionArgumentParser for processing CLI input
    */
   protected LDAPConnectionArgumentParser createArgParser(String className,
-                                           Message toolDescription)
-  {
+      Message toolDescription)
+    {
     ArgumentGroup ldapGroup = new ArgumentGroup(
             INFO_DESCRIPTION_TASK_LDAP_ARGS.get(), 1001);
 
@@ -191,6 +198,12 @@
                 FailedDependencyAction.defaultValue().name()));
       argParser.addArgument(failedDependencyActionArg, taskGroup);
 
+      testIfOfflineArg = new BooleanArgument(
+          "testIfOffline", null, "testIfOffline",
+          INFO_DESCRIPTION_TEST_IF_OFFLINE.get());
+      testIfOfflineArg.setHidden(true);
+      argParser.addArgument(testIfOfflineArg);
+
     } catch (ArgumentException e) {
       // should never happen
     }
@@ -351,6 +364,18 @@
                         PrintStream out, PrintStream err) {
     int ret;
 
+    if (testIfOffline())
+    {
+      if (!processAsTask())
+      {
+        return RUN_OFFLINE;
+      }
+      else
+      {
+        return RUN_ONLINE;
+      }
+    }
+
     if (processAsTask())
     {
       if (initializeServer)
@@ -449,4 +474,19 @@
     return argParser.connectionArgumentsPresent();
   }
 
+  /**
+   * Indicates whether we must return if the command must be run in offline
+   * mode.
+   * @return <CODE>true</CODE> if we must return if the command must be run in
+   * offline mode and <CODE>false</CODE> otherwise.
+   */
+  private boolean testIfOffline()
+  {
+    boolean returnValue = false;
+    if (testIfOfflineArg != null)
+    {
+      returnValue = testIfOfflineArg.isPresent();
+    }
+    return returnValue;
+  }
 }
diff --git a/opends/src/server/org/opends/server/util/SetupUtils.java b/opends/src/server/org/opends/server/util/SetupUtils.java
index 08716ff..5e19099 100644
--- a/opends/src/server/org/opends/server/util/SetupUtils.java
+++ b/opends/src/server/org/opends/server/util/SetupUtils.java
@@ -28,10 +28,8 @@
 
 
 
-import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -84,9 +82,6 @@
    */
   public static final String LIBRARIES_PATH_RELATIVE = "lib";
 
-  private static final String SET_JAVA_HOME_UNIX = "set-java-home";
-  private static final String SET_JAVA_HOME_WINDOWS = "set-java-home.bat";
-
   /**
    * Creates a MakeLDIF template file using the provided information.
    *
@@ -232,145 +227,6 @@
     return OperatingSystem.forName(System.getProperty("os.name"));
   }
 
-
-
-  /**
-   * Write a set-java-home file appropriate for the underlying platform that may
-   * be used to set the OPENDS_JAVA_HOME environment variable in a form suitable
-   * for the underlying operating system.  If a OPENDS_JAVA_HOME environment
-   * variable is currently set, then its value will be used.  Otherwise, it will
-   * be dynamically determined from the JVM properties.
-   * <BR><BR>
-   * Note that if the target file that would be written already exists, then
-   * this method will exit without doing anything and leaving the existing file
-   * intact.
-   *
-   *
-   * @param  serverRoot  The path to the root of the Directory Server instance
-   *                     for which the file will be written.
-   *
-   * @param overWrite when the set-java-home file exists whether to overwrite it
-   *        or not.
-   * @return  A handle to the {@code File} object that has been written.
-   *
-   * @throws  IOException  If a problem occurs while creating or writing to the
-   *                       specified file.
-   */
-  public static File writeSetOpenDSJavaHome(String serverRoot,
-      boolean overWrite) throws IOException
-  {
-    String javaHome = System.getenv(OPENDS_JAVA_HOME);
-    if ((javaHome == null) || (javaHome.length() == 0))
-    {
-      javaHome = System.getProperty("java.home");
-    }
-
-
-    File libDirectory = new File(serverRoot, LIBRARIES_PATH_RELATIVE);
-
-    File setJavaHomeFile;
-    if (isWindows())
-    {
-      setJavaHomeFile = new File(libDirectory, SET_JAVA_HOME_WINDOWS);
-      if (setJavaHomeFile.exists())
-      {
-        if (!overWrite)
-        {
-          return setJavaHomeFile;
-        }
-        else
-        {
-          File f1 = new File(javaHome);
-          File f2 = new File(getOpenDSJavaHome(serverRoot));
-          if (f1.equals(f2))
-          {
-            return setJavaHomeFile;
-          }
-        }
-      }
-      BufferedWriter writer =
-           new BufferedWriter(new FileWriter(setJavaHomeFile));
-      writer.write("set "+OPENDS_JAVA_HOME+"=" + javaHome);
-      writer.newLine();
-      writer.close();
-    }
-    else
-    {
-      setJavaHomeFile = new File(libDirectory, SET_JAVA_HOME_UNIX);
-      if (setJavaHomeFile.exists())
-      {
-        if (!overWrite)
-        {
-          return setJavaHomeFile;
-        }
-        else
-        {
-          File f1 = new File(javaHome);
-          File f2 = new File(getOpenDSJavaHome(serverRoot));
-          if (f1.equals(f2))
-          {
-            return setJavaHomeFile;
-          }
-        }
-      }
-      BufferedWriter writer =
-           new BufferedWriter(new FileWriter(setJavaHomeFile));
-      writer.write("#!/bin/sh");
-      writer.newLine();
-      writer.newLine();
-      writer.write(OPENDS_JAVA_HOME+"=" + javaHome);
-      writer.newLine();
-      writer.write("export "+OPENDS_JAVA_HOME);
-      writer.newLine();
-      writer.close();
-    }
-
-    return setJavaHomeFile;
-  }
-
-  /**
-   * Returns the java home value as it is specified in the set-java-home file.
-   * It returns <CODE>null</CODE> if the contents of the file are not valid, the
-   * file could not be read or if the file does not exist.
-   * @param  serverRoot  The path to the root of the Directory Server instance
-   *                     in which the set-java-home file is located.
-   * @return the java home value as it is specified in the set-java-home file.
-   * @throws  IOException  If a problem occurs while reading the file.
-   */
-  public static String getOpenDSJavaHome(String serverRoot) throws IOException
-  {
-    String javaHome = null;
-
-    File libDirectory = new File(serverRoot, LIBRARIES_PATH_RELATIVE);
-
-    File setJavaHomeFile;
-    if (isWindows())
-    {
-      setJavaHomeFile = new File(libDirectory, SET_JAVA_HOME_WINDOWS);
-    }
-    else
-    {
-      setJavaHomeFile = new File(libDirectory, SET_JAVA_HOME_UNIX);
-    }
-    if (setJavaHomeFile.exists())
-    {
-      BufferedReader reader =
-        new BufferedReader(new FileReader(setJavaHomeFile));
-      String line = reader.readLine();
-      String tag = OPENDS_JAVA_HOME+"=";
-      while ((line != null) && (javaHome == null))
-      {
-        int index = line.indexOf(tag);
-        if (index != -1)
-        {
-          javaHome = line.substring(index + tag.length());
-        }
-        line = reader.readLine();
-      }
-    }
-    return javaHome;
-  }
-
   /**
    * Returns {@code true} if the provided port is free and we can use it,
    * {@code false} otherwise.

--
Gitblit v1.10.0