Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "John B. Matthews" Newsgroups: comp.lang.java.programmer Subject: Re: Getting package info from JAR file Date: Tue, 04 Oct 2011 13:49:49 -0400 Organization: The Wasteland Lines: 43 Message-ID: References: NNTP-Posting-Host: LQJtZWzu+iKlBROuDg+IUg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8537 In article , markspace <-@.> wrote: > On 10/4/2011 6:51 AM, laredotornado wrote: > > > > I'm on Win XP using Java 7 but I have access to Unix tools using > > Cygwin. I was wondering, short of unzipping a JAR file and > > searching through it, if there's a way to figure out the package to > > which a class belongs, assuming I know the class name and that the > > JAR file definitely includes a class by this name. > > > Not really, no. If you don't know the package name, the class could > belong to any package. What package does the annotation @ManagedBean > belong too? Well, on my system, there are three ManagedBeans which > belong to different packages, so which one did you want? > > You've got to have the package name or you don't know which class it > is. You can narrow down the list of matching simple names like this: $ jar tf src.jar | grep "/Timer\." src/java/util/Timer.java src/javax/management/timer/Timer.java src/javax/swing/Timer.java And expand the search using find: $ find . -name \*.jar | xargs -I % jar tf % | grep "/Timer\." doc/api/java/util/Timer.html doc/api/java/util/class-use/Timer.html doc/api/javax/management/timer/Timer.html doc/api/javax/management/timer/class-use/Timer.html doc/api/javax/swing/Timer.html doc/api/javax/swing/class-use/Timer.html src/java/util/Timer.java src/javax/management/timer/Timer.java src/javax/swing/Timer.java -- John B. Matthews trashgod at gmail dot com