Document class file and information in Jar files.

Kent DyerAppl Systems Administrator - Assistant Vice President
CERTIFIED EXPERT
Published:
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a developer when researching a customer issue.  Most times when documenting issues, it is helpful to know where the problem exists and if you are able to replicate the issue: sounds like QA Testing for bug reports, doesn't it?  

It can help with research and documentation for issues seen when working cases for Java and Tomcat type of files. You will find when supporting Java products is that you can take a jar file and simply treat it as a zip file.  What is good about this is that you can put the information from your findings and the documented results in to  your Support Desk or SharePoint site so that you can search the information for what class under which jar file is giving the user a challenge..  I cannot take full credit for the ideas behind the process as I have borrowed pieces from http://www.robvanderwoude.com and I am using a COM Object (.dll) from http://www.xstandard.com to look inside these jar files.

Here is an example that you may see in real life - In troubleshooting, you may see a message like:
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Connection reset by peer: socket write error
      at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

So..  How do I know what Jar file that is in?  What class file do I need to look at?

Sure, you can go into Apache Tomcat (<Apache_Directory>\work\Catalina\localhost\PCC\org\apache\jsp\jsp ) and look at the problem .java file there or you can pull this information from an archive that you have generated from the csv file to help you in your troubleshooting with an issue.

What you will need to do is put in the location that you want to have the script go through and pull up the contents of the jar files..
Set oFSO = CreateObject("Scripting.FileSystemObject")
                      
                      Set fileOutput = oFSO.CreateTextFile(Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Jar_Files_Log.csv", True)
                      
                      Folders "C:\Tomcat 5.0"
                      
                      fileOutput.Close
                      
                      Function Folders(strFolder)
                      	Set oFSO = CreateObject("Scripting.FileSystemObject")
                      	Set objFolder = oFSO.GetFolder(strFolder)
                      	For Each Folder In Split(strFolder, ",")
                      		'WScript.Echo Folder
                      		Set objFolder = oFSO.GetFolder(Folder)
                      		''WScript.Echo objFolder.Path
                      		Set colFiles = objFolder.Files
                      		' -- Please note: This is necessary to show files
                      		' -- In a base folder (no subfolders)
                      		For Each objFile In colFiles
                      			If Right(objFile, 4) = ".jar" Then
                      				'WScript.Echo objFile.Name
                      				'WScript.Echo objFile.Path
                      				ZipContents objFile.Path
                      			End If
                      		Next
                      		' -- Recurse Subfolders
                      		ShowSubFolders(objFolder)
                      	Next
                      End Function
                      
                      Function ZipContents(ZipFile)
                      	' This function uses X-standards.com's X-zip component to extract files from a ZIP file.
                      	'
                      	' Arguments:
                      	' myZip         [string] the fully qualified path to the ZIP file
                      	' myTargetDir   [string] the directory where the extracted files will be located
                      	' myFileSpec    [string] the file(s) to be extracted, wildcards allowed
                      	'
                      	' Written by Rob van der Woude
                      	' http://www.robvanderwoude.com
                      	'
                      	' The X-zip component is available at:
                      	' http://www.xstandard.com/en/documentation/xzip/
                      	' For more information on available functionality read:
                      	' http://www.xstandard.com/printer-friendly.asp?id=C9891D8A-5390-44ED-BC60-2267ED6763A7
                      	Dim objZip, objItem
                      	Set objZip = CreateObject("XStandard.Zip")
                      	For Each objItem In objZip.Contents(ZipFile)
                      		'WScript.Echo ZipFile & "," & objItem.Path & objItem.Name
                      		If InStr(objItem.Name, ".") Then
                      			fileOutput.WriteLine Char(34) & ZipFile & Chr(34) & "," & objItem.Path & objItem.Name & "," & objItem.Size & "," & objItem.Date
                      		End If
                      	Next
                      	Set objZip = Nothing
                      	Set objItem = Nothing
                      End Function 
                      		
                      Sub ShowSubFolders(objFolder)
                      	Dim colFolders, objSubFolder
                      	Set colFolders = objFolder.SubFolders
                      	For Each objSubFolder In colFolders
                      		'WScript.Echo objSubFolder.Path
                      		'WScript.Echo objSubFolder
                      		Set colFiles = objSubFolder.Files
                      		For Each objFile In colFiles
                      			If Right(objFile, 4) = ".jar" Then
                      				'WScript.Echo objFile.Name
                      				'WScript.Echo objFile.Path
                      				ZipContents objFile.Path
                      			End If
                      		Next
                      		ShowSubFolders(objSubFolder)
                      	Next
                      End Sub

Open in new window


The results look similar to the following which will easily sorted in Excel (Note: This is just a sampling of the results generated):
Jar,location_and_file,size,file_date
C:\Tomcat 5.0\bin\bootstrap.jar,META-INF/MANIFEST.MF,277,8/28/2004 19:59
C:\Tomcat 5.0\bin\bootstrap.jar,org/apache/catalina/launcher/CatalinaLaunchFilter.class,1648,8/28/2004 19:59
C:\Tomcat 5.0\bin\bootstrap.jar,org/apache/catalina/loader/Reloader.class,248,8/28/2004 19:59

Have fun..

Kent
1
4,038 Views
Kent DyerAppl Systems Administrator - Assistant Vice President
CERTIFIED EXPERT

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.