Somebody must have solved this perennial problem that Java developersface

Discussion in 'Java' started by Ramon F Herrera, Dec 13, 2007.

  1. Let's say I download some library(s) and code. I load the code in my
    IDE and get several red lines telling me that some of the classes (for
    instance, XYZ) is not recognized. Well, time to add some(?) all(?)
    those libraries to the CLASSPATH, but which one(s)?

    I wish I had a command such as:

    % find javalib-folder -name XYZ.class

    Such command would navigate both kinds of filesystems (regular and
    jared) and tell me where the target class is hidden.

    Such a pervasive and simple to solve (not by me though!) problem, not
    to mention frustrating, annoying and counterproductive.

    My solution has been less than optimal. It involves renaming and
    unzipping too many files.

    -Ramon
     
    Ramon F Herrera, Dec 13, 2007
    #1
    1. Advertising

  2. Re: Somebody must have solved this perennial problem that Javadevelopers face

    On Dec 13, 10:56 am, Ramon F Herrera <> wrote:
    > Let's say I download some library(s) and code. I load the code in my
    > IDE and get several red lines telling me that some of the classes (for
    > instance, XYZ) is not recognized. Well, time to add some(?) all(?)
    > those libraries to the CLASSPATH, but which one(s)?
    >
    > I wish I had a command such as:
    >
    > % find javalib-folder -name XYZ.class
    >
    > Such command would navigate both kinds of filesystems (regular and
    > jared) and tell me where the target class is hidden.
    >
    > Such a pervasive and simple to solve (not by me though!) problem, not
    > to mention frustrating, annoying and counterproductive.
    >
    > My solution has been less than optimal. It involves renaming and
    > unzipping too many files.
    >
    > -Ramon


    grep can do this pretty nicely. I usually use

    $ grep -rl /NameOfClass.class ~/.m2/repository

    to search through the packages I have available locally.
     
    Owen Jacobson, Dec 13, 2007
    #2
    1. Advertising

  3. Re: Somebody must have solved this perennial problem that Javadevelopers face

    On Dec 13, 2:59 pm, Owen Jacobson <> wrote:
    > On Dec 13, 10:56 am, Ramon F Herrera <> wrote:
    >
    >
    >
    > > Let's say I download some library(s) and code. I load the code in my
    > > IDE and get several red lines telling me that some of the classes (for
    > > instance, XYZ) is not recognized. Well, time to add some(?) all(?)
    > > those libraries to the CLASSPATH, but which one(s)?

    >
    > > I wish I had a command such as:

    >
    > > % find javalib-folder -name XYZ.class

    >
    > > Such command would navigate both kinds of filesystems (regular and
    > > jared) and tell me where the target class is hidden.

    >
    > > Such a pervasive and simple to solve (not by me though!) problem, not
    > > to mention frustrating, annoying and counterproductive.

    >
    > > My solution has been less than optimal. It involves renaming and
    > > unzipping too many files.

    >
    > > -Ramon

    >
    > grep can do this pretty nicely. I usually use
    >
    > $ grep -rl /NameOfClass.class ~/.m2/repository
    >
    > to search through the packages I have available locally.


    Good to know! (and I thought I knew all about grep).

    Anybody knows of a solution for Windows?

    -Ramon

    ps: we need pattern matching, as well. The name of the class or jar
    doesn't have to be exact.
     
    Ramon F Herrera, Dec 13, 2007
    #3
  4. Ramon F Herrera

    Daniel Dyer Guest

    Re: Somebody must have solved this perennial problem that Java developers face

    On Thu, 13 Dec 2007 18:56:38 -0000, Ramon F Herrera <>
    wrote:

    > Let's say I download some library(s) and code. I load the code in my
    > IDE and get several red lines telling me that some of the classes (for
    > instance, XYZ) is not recognized. Well, time to add some(?) all(?)
    > those libraries to the CLASSPATH, but which one(s)?
    >
    > I wish I had a command such as:
    >
    > % find javalib-folder -name XYZ.class
    >
    > Such command would navigate both kinds of filesystems (regular and
    > jared) and tell me where the target class is hidden.
    >
    > Such a pervasive and simple to solve (not by me though!) problem, not
    > to mention frustrating, annoying and counterproductive.


    This has been discussed on here before. There were a few different
    solutions suggested. This is the shell script that I use (search the
    Google Groups archive for alternatives):

    #!/bin/sh
    find "$1" -name "*.jar" -exec sh -c 'jar -tf {}|grep -H --label {} '$2'' \;

    The first parameter is the directory to search recursively and the second
    parameter is a regular expression (typically just a simple class name) to
    search for. The script relies on the -t option to the jar command (which
    lists the contents) and greps each table of contents, labelling any
    matches with the path of the JAR file in which it was found.

    Dan.

    --
    Daniel Dyer
    http://www.uncommons.org
     
    Daniel Dyer, Dec 13, 2007
    #4
  5. Ramon F Herrera

    Daniel Dyer Guest

    Re: Somebody must have solved this perennial problem that Java developers face

    On Thu, 13 Dec 2007 19:04:12 -0000, Ramon F Herrera <>
    wrote:

    > On Dec 13, 2:59 pm, Owen Jacobson <> wrote:
    >>
    >> grep can do this pretty nicely. I usually use
    >>
    >> $ grep -rl /NameOfClass.class ~/.m2/repository
    >>
    >> to search through the packages I have available locally.

    >
    > Good to know! (and I thought I knew all about grep).
    >
    > Anybody knows of a solution for Windows?


    Cygwin. I don't understand how people can tolerate development on Windows
    without it.

    Dan.

    --
    Daniel Dyer
    http://www.uncommons.org
     
    Daniel Dyer, Dec 13, 2007
    #5
  6. Re: Somebody must have solved this perennial problem that Java developersface

    Owen Jacobson wrote:
    > On Dec 13, 10:56 am, Ramon F Herrera <> wrote:
    >> Let's say I download some library(s) and code. I load the code in my
    >> IDE and get several red lines telling me that some of the classes (for
    >> instance, XYZ) is not recognized. Well, time to add some(?) all(?)
    >> those libraries to the CLASSPATH, but which one(s)?
    >>
    >> I wish I had a command such as:
    >>
    >> % find javalib-folder -name XYZ.class
    >>
    >> Such command would navigate both kinds of filesystems (regular and
    >> jared) and tell me where the target class is hidden.
    >>
    >> Such a pervasive and simple to solve (not by me though!) problem, not
    >> to mention frustrating, annoying and counterproductive.


    I have a simple tool for finding classes from the classpath, not
    exactly what you want, but could be useful. Maybe I'll update it to do
    what you need.

    At http://tilialacus.net/projects/ download debugutil[*].

    You can run it with java -jar debugutil.jar for more info. Use
    java -cp debugutil.jar net.tilialacus.util.jwhich.JWhich <class>
    to find where in the classpath the file exists.

    //Roger Lindsjö

    * The need for this jar file came when I was doing on site support for a
    few companies that would not let us install any programs but would allow
    adding a jar file to the system. Many years ago, and I haven't touched
    the code since.
     
    Roger Lindsjö, Dec 13, 2007
    #6
  7. Ramon F Herrera

    Arne Vajhøj Guest

    Re: Somebody must have solved this perennial problem that Java developersface

    Ramon F Herrera wrote:
    > On Dec 13, 2:59 pm, Owen Jacobson <> wrote:
    > grep can do this pretty nicely. I usually use
    >>
    >> $ grep -rl /NameOfClass.class ~/.m2/repository
    >>
    >> to search through the packages I have available locally.

    >
    > Good to know! (and I thought I knew all about grep).
    >
    > Anybody knows of a solution for Windows?


    There are plenty of grep implementations for Windows.

    Cygwin comes with a GNU grep.

    Most Borland development tools comes with one.

    Probably others as well.

    I prefer the GNU version.

    Arne
     
    Arne Vajhøj, Dec 13, 2007
    #7
  8. Ramon F Herrera

    Roedy Green Guest

    Roedy Green, Dec 13, 2007
    #8
  9. Re: Somebody must have solved this perennial problem that Javadevelopers face

    On Dec 13, 7:56 pm, Ramon F Herrera <> wrote:
    > Let's say I download some library(s) and code. I load the code in my
    > IDE and get several red lines telling me that some of the classes (for
    > instance, XYZ) is not recognized. Well, time to add some(?) all(?)
    > those libraries to the CLASSPATH, but which one(s)?


    Hire someone from RAC and let him do the leg work.
     
    Hunter Gratzner, Dec 13, 2007
    #9
  10. Re: Somebody must have solved this perennial problem that Java developers face

    On Thu, 13 Dec 2007 10:56:38 -0800 (PST), Ramon F Herrera wrote:

    > Let's say I download some library(s) and code. I load the code in my
    > IDE and get several red lines telling me that some of the classes (for
    > instance, XYZ) is not recognized. Well, time to add some(?) all(?)
    > those libraries to the CLASSPATH, but which one(s)?
    >
    > I wish I had a command such as:
    >
    > % find javalib-folder -name XYZ.class
    >
    > Such command would navigate both kinds of filesystems (regular and
    > jared) and tell me where the target class is hidden.
    >
    > Such a pervasive and simple to solve (not by me though!) problem, not
    > to mention frustrating, annoying and counterproductive.
    >
    > My solution has been less than optimal. It involves renaming and
    > unzipping too many files.
    >
    > -Ramon


    I think that all you need is this tool:
    Java Class Finder, works like a charm :))
    http://www.idesksoft.com/classfinder.html

    Ups. I just looked at their page, it seems that it isnt free any more, to
    bad :( But it's not that expensive 4.95$
     
    Jednostanicni organizam, Dec 14, 2007
    #10
  11. Re: Somebody must have solved this perennial problem that Java developers face

    On Thu, 13 Dec 2007 10:56:38 -0800 (PST), Ramon F Herrera wrote:
    > I wish I had a command such as:
    >
    > % find javalib-folder -name XYZ.class
    >
    > Such command would navigate both kinds of filesystems (regular and
    > jared) and tell me where the target class is hidden.


    It's not that difficult. I put this together in a couple of minutes
    and I'm sure you can modify it to behave exactly the way you want:

    #!/bin/bash

    if [ "$1" = "" ]; then
    echo usage: $0 classname
    exit 1
    fi

    class=$1
    where=.

    for j in $(find $where -name "*.jar"); do
    if jar tf $j | grep -wq $class ; then
    echo $j contains $class
    exit 0
    fi
    done

    exit 1

    /gordon

    --
     
    Gordon Beaton, Dec 14, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lerp

    somebody must know this

    Lerp, May 21, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    304
  2. dd711
    Replies:
    6
    Views:
    917
    Alex Hunsley
    Oct 1, 2004
  3. Replies:
    2
    Views:
    1,334
  4. Michael Bacarella
    Replies:
    26
    Views:
    1,420
    harri
    Nov 20, 2007
  5. Adam Short
    Replies:
    4
    Views:
    238
    Mark Schupp
    Apr 28, 2005
Loading...

Share This Page