Skip to Content

Introduction

There are times that you need to move or copy your MI installation directory to a different location and execute it at that new location. In cases for example when you have limited space left in the current installation drive and you need to move it to a different drive having a larger disk space; or when you are conducting a series of tests for multiple MI client installations; or in times when your MI installation directory has been altered or renamed.

After copying or moving the installation files or renaming of installation path, you need to reconfigure or modify some of the files which holds persistent/static info which are assigned during the installation process. This article describes how to reconfigure your MI client installation when you move/copy it into a different location or when you had altered its installation path; and illustrates how to automate this reconfiguration using DOS commands in a batch file.

Target MI Version

This article applies to SAP Mobile Infrastructure* 2.1* and 2.5 installed in desktop Windows.

What are affected

In cases described in the previous section , you need to modify the following files to reflect your new installation path.

File Name

Description

startup.bat

Batch file for starting up the MI client

shutdown.bat

Batch file for shutting down the MI client

listOfJars.txt

Text file which contains the classpath of the MI and deployed libraries

The startup.bat contains the DOS commands for setting the classpath and invoking the Startup java class of the MI client. Likewise, +shutdown.bat +contains the DOS commands for  shutting down an  MI client currently running in the background. Listing 1 shows you the structure of the startup.bat file and Listing 2 for the shutdown.bat. Our primary concern here is the

ME_HOME

variable which needs to be updated with your new location. Default MI installation directory will set it to your system’s Program Files\SAP Mobile Infrastructure   directory as shown in the listings. The

JAVA_EXE

and

JAVA_HOME

variables on the other hand need only be updated if you move or want to change your JDK’s installation location. Here, we will not touch these variable values and leave them intact as they were.

Listing 1. Startup.bat file sample

set ME_HOME=C:\Program Files\SAP Mobile Infrastructure

set JAVA_OPTIONS=

set JAVA_EXE=D:\00DEV\JDK\JDK14208\bin\java.exe

set JAVA_HOME=D:\00DEV\JDK\JDK14208

SET _OLDCP=%CLASSPATH%

set _MEJARS=

copy /b “%ME_HOME%\SetMejar.txt” + “%ME_HOME%\listOfJars.txt” “%ME_HOME%\setMeJar.bat”

call “%ME_HOME%\setMeJar.bat”

set _SSLJARS=

  if exist “%ME_HOME%\lib\jsse.jar” set SSLJARS=%MEHOME%\lib\jsse.jar

  if exist “%ME_HOME%\lib\jcert.jar” set SSLJARS=%SSLJARS%;%ME_HOME%\lib\jcert.jar

  if exist “%ME_HOME%\lib\jnet.jar” set SSLJARS=%SSLJARS%;%ME_HOME%\lib\jnet.jar

set CLASSPATH=%_MEJARS%;%_bootstrap_jars%;%_SSLJARS%

echo Using CLASSPATH: %CLASSPATH%

“%JAVA_EXE%” %JAVA_OPTIONS% com.sap.ip.me.core.Startup “-home:%ME_HOME%” %1 %2 %3 %4 %5 %6 %7 %8 %9

SET CLASSPATH=%_OLDCP%

Listing 2. Shutdown.bat file sample

set ME_HOME=C:\Program Files\SAP Mobile Infrastructure

set JAVA_OPTIONS=

set JAVA_EXE=D:\00DEV\JDK\JDK14208\bin\java.exe

set JAVA_HOME=D:\00DEV\JDK\JDK14208
SET _OLDCP=%CLASSPATH%

set _MEJARS=

copy /b “%ME_HOME%\SetMejar.txt” + “%ME_HOME%\listOfJars.txt” “%ME_HOME%\setMeJar.bat”

call “%ME_HOME%\setMeJar.bat”

set CLASSPATH=%_MEJARS%;%_bootstrap_jars%

echo Using CLASSPATH: %CLASSPATH%

“%JAVA_EXE%” %JAVA_OPTIONS% com.sap.ip.me.core.Startup “-home:%ME_HOME%” -stop %1 %2 %3 %4 %5 %6 %7 %8 %9

SET CLASSPATH=%_OLDCP%

Perhaps you might have noticed already, the +startup.bat + and +shutdown.bat +does not differ that much. Only the

-stop

parameter is added as a parameter to the java Startup class. The common lines should have been moved into a common script… Anyway, seems that we have a part of it subject for refactoring 🙂 .

To move on, the listOfJars.txt contains the classpath of the MI libraries and its contents is added to the classpath entries which is passed as argument when invoking the Startup program. Listing 3 shows a sample contents of the listOfJars.txt file. After moving or renaming the MI installation directory, the paths to the referenced Java libraries which are listed in this file should be updated with the new location. 

Listing 3. listOfJars.txt sample

C:\Program Files\SAP Mobile Infrastructure\lib\ME.jar;C:\Program Files\SAP Mobile Infrastructure\lib\system\xalan.jar;C:\Program Files\SAP Mobile Infrastructure\lib\system\jaxp.jar;C:\Program Files\SAP Mobile Infrastructure\lib\system\crimson.jar;C:\Program Files\SAP Mobile Infrastructure\lib\pinstall.jar;

The three files described have static data related to the path of the MI installation directory. Opening these files with a text editor like a Notepad and replacing the old path with the new one requires some steps of opening files, copy & paste and saving the files… Is there a way to automate this? Well, the next section illustrates on how to do it using the internal DOS commands in Windows desktop.

Automating the reconfiguration procedures

In this section I will describe how to modify the ME_HOME variable in the+ startup.bat+ and shutdown.bat files using another batch file to process it. Then I will proceed on how to update the listOfJars.txt; listing up all jar files found inside the lib directories and its sub-directories. Take note that all the scripts describe here must be executed from the MI root directory.

Listing 4. Modifying startup & shutdown batch files

SETLOCAL

SET TARGETFILE=startup.bat

echo off

find /V /I “set me_home” %TARGETFILE%>t1.tmp

echo SET ME_HOME=%cd%>t0.tmp

copy /Y t0.tmp+t1.tmp %TARGETFILE%

del /Q t0.tmp

del /Q t1.tmp

echo on

ENDLOCAL

Listing 4 is the batch file for modifying the ME_HOME variable value found within the startup and shutdown batch files. Here’s how it works:

First, we set our target file to startup.bat, then we search for the line having the string “set me_home” within the target file using the find command. Rather than giving us the line/s which have that string, we instead use the /V switch to give us all the lines excluding the line/s which have that search string found in it. What we did here actually was removed the lines having the string “set me_home” regardless of the case indicated by the /I switch. We put the result into a temporary file named t1.tmp. Then we used the echo command to give us the string “SET ME_HOME=<current directory>” where the  is the output of the special variable %cd%. The output of this command is saved into t0.tmp. Next, we used the copy command to concatenate the t0 and t1 files; overwriting the target file which is the startup.bat file. Lastly, we did the cleaning of the temporary files. To modify the shutdown batch file, you have to change the value of the TARGETFILE variable to shutdown.bat and run the same procedures.

We’ll now proceed on our classpath re-configuration batch file. Listing 5 shows the batch file command for searching the jar files and updating the listOfJars.txt content.

Listing 5. Classpath re-configuration batch file

SETLOCAL

set JARFILENAME=listOfJars.txt

del /s %JARFILENAME%

cd lib

set MEJARFILES=

echo set MEJARFILES=%%~1;%%MEJARFILES%%>append.bat

echo off

dir /s/b *.jar > tmpList.txt

FOR /F “usebackq tokens=1* delims=” %%i IN (tmpList.txt) do (call append.bat “%%i”)

echo %MEJARFILES% > %JARFILENAME%

move /Y %JARFILENAME% ..

del /s append.bat

del /s tmpList.txt

cd ..

endlocal

On the first part of the script, we set the JARFILENAME variable value to listOfJars.txt, then we delete the current listOfJars.txt file from the directory. We then move to the lib location where we will look for the JAR files. Next we declared the variable named MEJARFILES which will hold the entries of the path to the jar files. Then, we created a simple utility batch file named append.bat which we will use when we loop into the found jar files later. This batch file simply inserts the argument passed during the call invocation into variable MEJARFILES. Next, we search for all the files having an extension name of .jar from the current +lib +folder and its subfolders using the command dir. We saved the results into a temporary file named tmpList.txt, which contains the absolute path to the jar files inside the lib and its sub-folders in a one entry per line structure. However, we need to append them into one line for our classpath. Here, using the for command, we loop into all the entries in the tmpList.txt and use the utility batch file we created to append them for us. We then put the appended jar file path entries which is the value of the MEJARFILES variable into the listOfJars.txt file. And since we are working currently inside the lib directory+, + we have to move it to the MI root folder which is the parent folder. Lastly, we did the cleaning up and move back to the MI root directory.

Listing 6. The MI reconfiguration batch file

SETLOCAL

SET TARGETFILE=startup.bat


echo off

find /V /I “set me_home” %TARGETFILE%>t1.tmp

echo SET ME_HOME=%cd%>t0.tmp

copy /Y t0.tmp+t1.tmp %TARGETFILE%

del /Q t0.tmp

del /Q t1.tmp

SET TARGETFILE=shutdown.bat


echo off

find /V /I “set me_home” %TARGETFILE%>t1.tmp

echo SET ME_HOME=%cd%>t0.tmp

copy /Y t0.tmp+t1.tmp %TARGETFILE%

del /Q t0.tmp

del /Q t1.tmp

set JARFILENAME=listOfJars.txt

del /s %JARFILENAME%

cd lib

set MEJARFILES=

echo set MEJARFILES=%%~1;%%MEJARFILES%%>append.bat

dir /s/b *.jar > tmpList.txt

FOR /F “usebackq tokens=1* delims=” %%i IN (tmpList.txt) do (call append.bat “%%i”)

echo %MEJARFILES% > %JARFILENAME%

move /Y %JARFILENAME% ..

del /s append.bat

del /s tmpList.txt

cd ..

ENDLOCAL

To put things all together, Listing 6 shows you batch file which will do all the modification for all the affected files described in the previous section. Save this listing into e.g. MIReconf.bat under your MI root installation directory and execute it from there.

Now, somebody might ask, “can I modify the script making the installation path be detected during runtme?”. Well, yes. The answer is already described above. And the next section will show you how.

The alternative

In the previous section, I described the procedures on how to modify the existing batch files and classpath entries by correcting the ME_HOME variable value  to that of the current directory. And that our automation tool will correct these values to the new location. However, if your installation path got altered again, you need to run the+ reconfiguration script +to reflect the changes into the scripts. Now, rather than creating the reconfiguration in Listing 6, let’s try modifying the startup and shutdown scripts directly. We are going to avoid making the installation path persistent into the files; i.e. we’re going to use some variable/s that will be process  at runtime and will be assigned to our variable ME_HOME.

In Listings 1 & 2, we changed the value of the ME_HOME variable to its current directory. Now, declaring its value as shown below, the variable will be assigned with the current directory where the script is executed, which is the root installation folder.

 

set ME_HOME=%cd%

In the same listings, the following lines only set the variable _MEJARS variable with the classpath entries; and we can make this variable values be processed during runtime.

 

set _MEJARS=

copy /b “%ME_HOME%\SetMejar.txt” + “%ME_HOME%\listOfJars.txt” “%ME_HOME%\setMeJar.bat”

call “%ME_HOME%\setMeJar.bat”

So we’ll alter these lines as follows:

 

set _MEJARS=

    echo set MEJARS=%%~1;%%MEJARS%%>append.bat

dir /s/b lib\*.jar > tmpList.txt

FOR /F “usebackq tokens=1* delims=” %%i IN (tmpList.txt) do (call append.bat “%%i”)

del /s append.bat

del /s tmpList.txt

And our final startup and shutdown batch files will look like as shown in Listing 7 and 8. This is just a one time modification of both scripts and any alterations in the installation path or your libraries will not require the scripts to be modified. Thus, you can move or rename your MI installation now without having to reconfigure it corresponding to the change in the installation path. The only static variables we have left are the JAVA_EXE and JAVA_HOME, and they only required to be modified when the path to your JDK is altered or when you want to use a specific JDK version for your MI.

Listing 7. Modified Startup.bat file

set ME_HOME=%cd%

set JAVA_OPTIONS=

set JAVA_EXE=D:\00DEV\JDK\JDK14208\bin\java.exe

set JAVA_HOME=D:\00DEV\JDK\JDK14208

SET _OLDCP=%CLASSPATH%

set _MEJARS=

echo set MEJARS=%%~1;%%MEJARS%%>append.bat

dir /s/b lib\*.jar > tmpList.txt

FOR /F “usebackq tokens=1* delims=” %%i IN (tmpList.txt) do (call append.bat “%%i”)

del /s append.bat

del /s tmpList.txt

set _SSLJARS=

        if exist “%ME_HOME%\lib\jsse.jar” set SSLJARS=%MEHOME%\lib\jsse.jar

        if exist “%ME_HOME%\lib\jcert.jar” set SSLJARS=%SSLJARS%;%ME_HOME%\lib\jcert.jar

        if exist “%ME_HOME%\lib\jnet.jar” set SSLJARS=%SSLJARS%;%ME_HOME%\lib\jnet.jar

set CLASSPATH=%_MEJARS%;%_bootstrap_jars%;%_SSLJARS%

echo Using CLASSPATH: %CLASSPATH%

“%JAVA_EXE%” %JAVA_OPTIONS% com.sap.ip.me.core.Startup “-home:%ME_HOME%” %1 %2 %3 %4 %5 %6 %7 %8 %9

SET CLASSPATH=%_OLDCP%

Listing 8. Modified Shutdown.bat file

set ME_HOME=%cd%

set JAVA_OPTIONS=

set JAVA_EXE=D:\00DEV\JDK\JDK14208\bin\java.exe

set JAVA_HOME=D:\00DEV\JDK\JDK14208

SET _OLDCP=%CLASSPATH%

set _MEJARS=

echo set MEJARS=%%~1;%%MEJARS%%>append.bat

dir /s/b lib\*.jar > tmpList.txt

FOR /F “usebackq tokens=1* delims=” %%i IN (tmpList.txt) do (call append.bat “%%i”)

del /s append.bat

set CLASSPATH=%_MEJARS%;%_bootstrap_jars%

echo Using CLASSPATH: %CLASSPATH%

“%JAVA_EXE%” %JAVA_OPTIONS% com.sap.ip.me.core.Startup “-home:%ME_HOME%” -stop %1 %2 %3 %4 %5 %6 %7 %8 %9

SET CLASSPATH=%_OLDCP%

This alternative has also the advantage of ensuring that all of the jar files found in the library are added without having to worry in cases when they were renamed or moved into subfolder/s. This also requires you to modify the startup and shutdown scripts manually but doesn’t require you to create the reconfiguration script shown in Listing 6.

Caveat:

Just take note however that the way we append our libraries into the classpath is pretty random and it will add all the jar files found in the lib folder and its sub-folders . If you require your libraries to appear into your classpath in a specific order and/or has some jar files that don’t want to be appended in the classpath, I guess you need to modify the scripts specifying the names of the  files and their specific order. And this might require you to make your classpath statically specified rather than  making it dynamic.

By the way, if you are invoking your MI client thru a shortcut link to your mobileengine.exe, you have to modify your shortcut icon’s property with the proper installation path.  </p>

Summary

I described the procedures on how to re-configure an MI installation in cases when the installation path has been altered. I hope that this info will be useful in a way or another on your MI related tasks; and that the described automation tips will help you save time and energy from manually modifying the static data found in the scripts. And that by making your scripts a little bit dynamic using the alternative method, you’re relieved from your worries of having to reconfigure it again when the installation path is altered. Lastly, I do hope that this little modification in the scripts described here will be included in the future release of MI client, freeing us all with this manual alteration of the scripts.

Well, till here… and see you on my next blog.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply