Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
5,466

Have you ever encounter a situation where you need a specific class when developing a User-Defined Function, User-Module, or Java Mapping, and don’t know which jar file contains this class.  I get calls from many PI developers with this situation asking me what is the jar filename containing the needed class.  In almost all situations, I was able to respond immediately.  In this blog, I will reveal how this can be done quickly.

I have a text file containing the following information:  jar file name, class path and class name.  By searching for the class name, I can find all the class paths and jar file names where this class name exists.  In order to create this file, I have to do the following in a Windows environment:

1.     Retrieve all the jar files in PI.  This can be done by doing a search for “*.jar” in the directory “…\j2ee\cluster” (including subdirectory), and copy all of them to a temporary location.  During the process, let it override duplicate file names.  (This can be time-consuming process, but it only needs to be done once, and it is worth it.)

2.     Execute the following BAT file, in the same directory as the jar files, to produce the desired text file:

BAT file content:

@Echo OFF

set JAVAPATH=C:\jdk1.6.0_27\bin

set JARFILES=_myJarFiles.txt

set JARLIST=_myJarList.txt

set CLASSLIST=_classList.txt

set PATH=c:\jdk1.6.0_18\bin

dir /b *.jar > %JARFILES%

del %JARLIST%

For /F "tokens=1" %%A IN (%JARFILES%) DO (

   echo ***%%A >> %JARLIST%

   %JAVAPATH%\jar tf %%A >> %JARLIST%

)

%JAVAPATH%\java -classpath C:\jars\ListJavaClasses.jar com.util.GetJavaClasses %JARLIST% %CLASSLIST%

del %JARFILES% %JARLIST%

pause

Please note:

      • JAVAPATH contains the java J2SE installation
      • Modify the locatoin of the ListJavaClasses.jar file as appropriate
      • ListJavaClasses.jar contains the GetJavaClasses program to parse the data  (the GetJavaClasses.java program is listed below):
package com.util;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

public class GetJavaClasses {
     
     public void processJarList(InputStream is, OutputStream os) {
          String blanks = "                                                       ";
          try {
               String line = null;
               String jarName = null;
               BufferedReader in = new BufferedReader(new InputStreamReader(is));
               try {
                    while ((line = in.readLine()) != null) {
                         if (line.length() < 10) continue;
                         if (line.substring(0,3).equals("***")) {
                              jarName = line.substring(3) + blanks;
                              jarName = jarName.substring(0, 60);
                         }
                         else {
                              int l = line.length();
                              if (line.indexOf(".class", l-7) >= 0) {
                                   String className = jarName + line + "\n";     
                                   writeOutStream(os, className);
                              }
                         }
                    }
                    in.close();
                    os.close();
               }
               catch (Exception e) {
                    e.printStackTrace();
               }
          }
          catch (Exception e) {
               System.out.println("Error: " + e.getMessage());
          }
     }

     private void writeOutStream(OutputStream out, String val) {
          byte[] b = val.getBytes();
          try {
               out.write(b);
          }
          catch (Exception e) {
               e.printStackTrace();
          }
     }
     
     /**
      * @param args
      */
     public static void main(String[] args)  throws Exception{
          String inFile = args[0];               // "/jars/710/_myJarList.txt";
          String outFile = args[1];
          InputStream in = new BufferedInputStream(
               new FileInputStream(inFile));
          FileOutputStream out = new FileOutputStream(outFile);          //"/jars/710/_myClassList.txt");
          GetJavaClasses test = new GetJavaClasses();
          test.processJarList(in, out);
          System.out.println("done");
     }

}

3.     Sample content of the text file (_classList.txt):

          
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/Arithm.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/Bool.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/CalendContainer.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/CollapseContexts.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/Constant.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/Counter.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/CurDate.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/DateFunctions.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/DateTransformer.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/Dummer.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/Exists.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/If.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/IfS.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/IfSWithoutElse.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/IfWithoutElse.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/MessageHeader.class
com.sap.xi.mapping.tool.lib_api.jar                         com/sap/aii/mappingtool/flib3/NodeConst.class
1 Comment