We Recommend

Smarty PHP Template Programming And Applications Smarty PHP Template Programming And Applications
Smarty is a templating engine for PHP. Designers who are used to working with HTML files can work with Smarty templates, which are HTML files with simple tags while programmers work with the underlying PHP code. The Smarty engine brings the code and templates together. The result of all this is that designers can concentrate on designing, programmers can concentrate on programming, and they don't need to get in each others way so much.


Posted By

thebugslayer on 06/04/07


Tagged

java jar


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

liqweed


Search entry in jar files


Published in: Groovy 


Eg: groovy findjar "Servlet" /opt/tomcat/lib


  1. #!/usr/bin/env groovy
  2.  
  3. import java.util.jar.*
  4.  
  5. //Usage check.
  6. if(args.size() <2){
  7. println "usage: ${this.class.name} searchstr jarfile [jarfile]"
  8. println " jarfile can be a directory, which will include all jar files."
  9. }
  10.  
  11. //Collect args for jar files.
  12. searchstr = args[0]
  13. jarfiles = []
  14. args[1..-1].each{ arg->
  15. file = new File(arg)
  16. if(file.isDirectory()){
  17. file.eachFileMatch(~/.*\.jar$/){ jarfiles.add(it) }
  18. }else{
  19. jarfiles.add(file)
  20. }
  21. }
  22. //println binding.variables
  23.  
  24. //Find and print the entry listing!
  25. jarfiles.each{ file->
  26. jarfile = new JarFile(file)
  27. jarfile.entries().each{ entry->
  28. if (entry.name =~ searchstr){
  29. println "$entry.name : $file.canonicalPath"
  30. }
  31. }
  32. }

Report this snippet 

You need to login to post a comment.