Rcjp's Weblog

October 11, 2006

Find classes in java jar files

Filed under: lisp, utils — rcjp @ 1:57 pm

;;; Find classes in jar files
;;; Usage (findjar classname directory)
;;; e.g (findjar "session" "c:/Novell/ndk/njclv2/lib")
(defun findjar (classname dir)
  ;;  (if (not (directory dir))
  ;;(format t "Invalid directory syntax - remember a trailing slash")
  (dolist (file (directory (concatenate 'string dir "/**/*")))
    (when (string-equal (pathname-type file) "JAR")
      (format t "processing ~S~%" file)
      (with-open-stream (str
        (run-program (concatenate 'string "jar tf " (namestring file)) :output :stream)
        #+ clisp
        (ext:run-program "jar" :arguments (list "tf" (namestring file)) :output :stream)
        #+ lispworks
        (sys:open-pipe (concatenate 'string "jar tf " (namestring file)))
        (loop for line = (read-line str nil nil)
              while line
              (when (search classname line :test 'string-equal)
                (format t "   found->~S in file (~S)~%" line (namestring file))


Leave a Comment »

No comments yet.

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: