Somebody must have solved this perennial problem that Java developersface

R

Ramon F Herrera

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
 
O

Owen Jacobson

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.
 
R

Ramon F Herrera

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.
 
D

Daniel Dyer

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.
 
D

Daniel Dyer

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.
 
R

Roger Lindsjö

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.
 
A

Arne Vajhøj

Ramon said:
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
 
H

Hunter Gratzner

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.
 
J

Jednostanicni organizam

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$
 
G

Gordon Beaton

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

--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top