Java Tip : How to locate class files in a jar jungle

This is one command that I find very useful at work. I learned it from my Collegue Manish.

If you have lot of jar files lying in some directories and you want to find which jar file contains Foo.class,

for i in `find . -name “*.jar”`; do echo $i; jar tvf $i | grep “Foo”; done

For Windows users, this might be a full day work, rite? Enjoy!

How to connect to remote x11 server

Following are the steps to connect to a remote x11 server,

On the client machine set the DISPLAY variable as follows,

$ export DISPLAY=server-host-name:0.0

On the server machine, enable remote connection from client

$ xhost +

N.B – use + if you are not concerned about any security issues. It enables any one to connect to your server. Use specific client name otherwise.
To read more about reasons to use remote display server and better security options , check this link.

rgrep equivallent on Solaris

There is no recursive grep function on Solaris. The work around that we use at work is,

find ./ -name *.java | xargs grep “mystring”

Suppose you want to find all Java class files under a given directory, including the sub directories, that use the resource bundle key “prop.file.path”

First part of the command returns all the files with .java extension –
find ./ -name *.java

The output of find command is given as input to the grep command using pipe symbol. xargs (http://en.wikipedia.org/wiki/Xargs) is used to split the large number of results returned by find command and pass it one by one to grep.

find ./ -name *.java   | xargs grep “prop.file.path”