Skip to Content

Overview

Have you ever been working on a program and wonder what jar contains the classes you require? Have you ever run into a case where more than one class with the same name is available in your code? Have you ever noticed the JAVA APIs never tell you what jar a class comes from? I have, many times. I have used the following perl script to retrieve a list of classes from each jar in the path I point the script to.

DISCLAIMER: YOU ARE USING THIS CODE AT YOUR OWN RISK. GREGORY CABLE AND HIS AFFILIATES MAY NOT BE HELD LIABLE FOR ANY NEGATIVE EFFECTS YOU EXPERIENCE IN USING THIS CODE. THIS CODE IS PROVIDED AS IS – BY USING THIS CODE YOU ACCEPT FULL RESPONSIBILITY. YOU ARE ALSO RESPONSIBLE FOR ANY MODIFICATIONS MADE TO THIS CODE.

Requirements:

  • You must have Perl installed
  • You must have BOBJ installed (jars and unzip will come form the install)
  • The code provided


Steps:

  • Add the following code to a file. The name getBOBJClassList.pl works.
Perl Script

# Declaring variables, in perl you don’t have to by default but it is a good habit
my (@classInventory, @dirList, $file, @classList, $class, $unzipPath);
$unzipPath = “C:\\Program Files (x86)\\SAP BusinessObjects\\InstallData\\InstallCache\\setup.core-4.0-core-32\\14.1.5.1501\\actions\\“;
print “$unzipPath\n”;
# This is the dir to change as needed, again make sure you escape the backslashes with back slashes
$dir = “C:\\Program Files (x86)\\SAP BusinessObjects\\SAP BusinessObjects Enterprise XI 4.0\\classes\\“;
# Here we are using backtick operators (shift-tilde)
# They tell the perl engine to run the enclosed code as a system command
# BTW, an ampersand is a list or array in perl, basically I am taking the directory and pumping it into a list of values
# The /b causes dir to return nothing but the path and the file name
# The /s causes dir to search sub-directories, it forces the search to be recursive
@dirList = `dir /b/s “$dir*”`;
@iterate through our list and assign each value to $fileforeach $file(@dirList)

{
# Simply stripping the carriage return off the end of the string
chomp($file);
# A regular expression. I am essentially saying give me all files that END with .zip or .jar,
# The dollar sign is what tells it to match at the end of the string
# The =~ is telling it to look at the string \$file,  without it perl would look at the default variable \$_
if ($file =~ /\.jar$/ or $file =~ /\.zip$/)
{
# Again, use the backtick operator to get the information from unzip

@classList = `”${unzipPath}unzip” -l “$dir$file”`;

foreach $class(@classList)
{
#  Push simply puts the value onto the end of the list, it auto increments so no redim or playing around is needed
push @classInventory, “$file:\t$class”;
                }

}

}

# I didn’t strip out the carriage return on the results of the unzip so I don’t have to add them back here
# I will just dump the entire list to the screen here.
print @classInventory;

exit;

  • Replace the path between the quotes on the line that starts with “$unzipPath = “. You can search for “unzip.exe” on your drive, be sure to add \\ to the end of the path and make each \ within the path \\ (escapes it so perl knows it is a literal backslash).
  • Replace the path between the quotes on the line that starts with “$dir = “. This is the path that contains the jar files from which you wish to extract the class information. Once again, be sure to add \\ to the end of the path and make each \ within the path \\ (escapes it so perl knows it is a literal backslash).
  • Run the perl script. This can take a while to run.


Additional Information:

  • To use the list, simply replace the “.” in your import statement with “/” and search the results of the script. Note that we could have programmatically replaced the “/” with “.” in the script using regular expressions.
  • We could also use command line substitutions to set the paths, I don’t see the point since I have to modify them text by adding backslashes anyway.
  • Finally, rather than dumping the results to standard out you can always create a file.

TIP: When the script is running it will be dumping a line out for every class found in the jar files. The screen print takes a lot of resources. If you minimize the screen or re-size the screen so very few rows are displayed the process will complete much quicker.

Result Sample

C:\Program Files (x86)\SAP BusinessObjects\InstallData\InstallCache\setup.core-4.0-core-32\14.1.5.1501\actions\

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar: Archive:  C:/Program Files (x86)/SAP BusinessObjects/SAP BusinessObjects Enterprise XI 4.0/java/lib/activation.jar

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:  Length      Date    Time    Name

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar: ———  ———- —–   —-

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     4013  04/19/2006 08:11   META-INF/MANIFEST.MF

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     3745  04/19/2006 08:11   META-INF/SUN_MICR.SF

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     3771  04/19/2006 08:11   META-INF/SUN_MICR.RSA

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:        0  04/19/2006 08:10   META-INF/

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      292  04/19/2006 08:10   META-INF/mailcap.default

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      581  04/19/2006 08:10   META-INF/mimetypes.default

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:        0  04/19/2006 08:10   javax/

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:        0  04/19/2006 08:10   javax/activation/

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     2093  04/19/2006 08:10   javax/activation/ActivationDataFlavor.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     3611  04/19/2006 08:10   javax/activation/MimeType.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     3639  04/19/2006 08:10   javax/activation/MimeTypeParameterList.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      324  04/19/2006 08:10   javax/activation/MimeTypeParseException.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     1304  04/19/2006 08:10   javax/activation/CommandInfo.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     1207  04/19/2006 08:10   javax/activation/DataHandler$1.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     8412  04/19/2006 08:10   javax/activation/DataHandler.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      346  04/19/2006 08:10   javax/activation/DataSource.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     2279  04/19/2006 08:10   javax/activation/CommandMap.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      598  04/19/2006 08:10   javax/activation/DataContentHandler.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      243  04/19/2006 08:10   javax/activation/DataContentHandlerFactory.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      254  04/19/2006 08:10   javax/activation/CommandObject.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      835  04/19/2006 08:10   javax/activation/DataHandlerDataSource.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     2090  04/19/2006 08:10   javax/activation/DataSourceDataContentHandler.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     2115  04/19/2006 08:10   javax/activation/ObjectDataContentHandler.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     1346  04/19/2006 08:10   javax/activation/FileDataSource.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     1534  04/19/2006 08:10   javax/activation/FileTypeMap.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     9491  04/19/2006 08:10   javax/activation/MailcapCommandMap.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     5663  04/19/2006 08:10   javax/activation/MimetypesFileTypeMap.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      563  04/19/2006 08:10   javax/activation/SecuritySupport$1.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      699  04/19/2006 08:10   javax/activation/SecuritySupport$2.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     1173  04/19/2006 08:10   javax/activation/SecuritySupport$3.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     1088  04/19/2006 08:10   javax/activation/SecuritySupport$4.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      592  04/19/2006 08:10   javax/activation/SecuritySupport$5.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     1724  04/19/2006 08:10   javax/activation/SecuritySupport.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     1201  04/19/2006 08:10   javax/activation/URLDataSource.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      336  04/19/2006 08:10   javax/activation/UnsupportedDataTypeException.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:        0  04/19/2006 08:10   com/

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:        0  04/19/2006 08:10   com/sun/

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:        0  04/19/2006 08:10   com/sun/activation/

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:        0  04/19/2006 08:10   com/sun/activation/registries/

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     7029  04/19/2006 08:10   com/sun/activation/registries/MailcapFile.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      335  04/19/2006 08:10   com/sun/activation/registries/MailcapParseException.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     3287  04/19/2006 08:10   com/sun/activation/registries/MimeTypeFile.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      734  04/19/2006 08:10   com/sun/activation/registries/MimeTypeEntry.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     1862  04/19/2006 08:10   com/sun/activation/registries/LineTokenizer.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     1605  04/19/2006 08:10   com/sun/activation/registries/LogSupport.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     3616  04/19/2006 08:10   com/sun/activation/registries/MailcapTokenizer.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:        0  04/19/2006 08:10   com/sun/activation/viewers/

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     2569  04/19/2006 08:10   com/sun/activation/viewers/ImageViewer.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:      928  04/19/2006 08:10   com/sun/activation/viewers/ImageViewerCanvas.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     4003  04/19/2006 08:10   com/sun/activation/viewers/TextEditor.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:     1803  04/19/2006 08:10   com/sun/activation/viewers/TextViewer.class

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar: ———                     ——-

C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib\activation.jar:    94933                     51 files

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