Friday, February 5, 2010

Jar Scanning

Sometimes it can be helpful to track down where exactly a class is within a library of jars.

One means of doing it is to run something like the following from the command line:

find . -name \*jar -print -exec jar -tvf {} \; | nawk '/YOURSEARCHSTRING/ || /jar/ {print} '

Another means is to use a java based jarscan tool.
The tool comes with a .bat file, which is not exactly ideal for linux development.
I created an equivalent .sh file with the following contents:

java -jar $JARSCAN_HOME/jarscan.jar $1 $2

and added an alias to my ~/.bashrc file of the form:

alias jarscan='~/dev/apps/jarscan/'

Now you have a command line jarscanner. Navigate to any directory, and to run a recursive jar search enter a short command like the following:

jarscan MBeanServer

Maven Tricks

see all the libs that end up on the classpath of your maven project:

mvn dependency:build-classpath | sed 's/:/\n/g' > cp.txt

Jar search:
find . -name \*jar -print -exec jar -tvf {} \; | nawk '/YOURSEARCHSTRING/ || /jar/ {print} '

or use jarscan tool

bash script:
java -jar $JARSCAN_HOME/jarscan.jar $1 $2

alias added to .bashrc:
alias jarscan='~/dev/apps/jarscan/'

and your good to go. Now you can run a recursive search of jars in any directory with a command like:
jarscan MBean

The Wonder of GIT

Setup your identity:

git config --global "FirstName LastName"
git config --global ""

Make git a little prettier:

git config --global color.ui "auto"

The basic format of the push operation is:

git push $repository-location $source-branch:$dest-branch

Publish a local branch, remotely:

git push origin $local-branch:$remote-branch

Delete a remote branch:

git push origin :$remote-ref

Once a remote branch is deleted, other team members must delete references to the deleted branches by running:

git remote prune origin

Create a local branch to track a remote branch:

git branch --track local-branch-2 origin/remote-branch-2

Work on a remote branch other than master

git fetch // to ensure git local knows about remote branch
git checkout --track -b $local-branch origin/$remote-branch

To find some code you previously had in a file

// Find the relevant commit
git log /path/to/file
// Now view the changes in that file since that particular commit
git diff $commitHash /path/to/file

To revert just one file to a previous commit
git checkout $commitHASH /path/to/file

To see who is responsible for the current state of a particular file:

git blame $fileName