• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Listing out all of the jar files in a .classpath file

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You know, this really drove me crazy today, because it is something that should be very simple to do.

I have two .classpath files, and I want to compare all of the jar files that they use. Since the path information may be different, I wanted to just get the list of everything '.jar'.

So a line like, '<classpathentry kind="lib" path="C:/apache-tomcat-8.0.99/lib/servlet-api.jar"/>', would just produce 'servlet-api.jar'

So I tried with grep and then sed and then java regex (Pattern and Matches) and finally String.split(). I finally got my what I wanted, but it wasn't pretty.

There has to be a simple way to use a regular expression to look through a file and get all /*.jar

What is it? And before you answer without testing your code, be advised, I must have tried 100 things that I was Sure would work, but did not.

Thanks in advance,
Skip
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i won't swear to it, but:
(.*)/([-a-z]*.jar)

seems to work for the line provided, according to my regex tool.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But these are XML files, aren't they? So I would just parse the two documents and find everything which matches the XPath expression "//classpath/@path". Then you just have two lists to compare.

Hopefully that isn't one of the 100 things you tried, because it's untested.
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic