[jboss-user] [EJB 3.0] - Re: javax.annotation.Resource

Alan D. Salewski asalewski at healthmarketscience.com
Wed Mar 28 08:23:05 EDT 2007


On Tue, Mar 27, 2007 at 08:03:20PM -0400, ebergerson spake thus:
> For that matter, how in general do you find the correct jar for any
> class using JBoss.  I have been looking for the correct jar for
> javax.ejb.Stateless for 2 hours.  Not a clue.
> 
> Given the wide range of jars, and the number of locations (/lib,
> /client, /server//lib) they live in, really, how do you know which jar
> contains which classes?

I've created a 'findclass' program that helps with this.

Example usage:

    $ findclass /usr/local/jboss-4.0.5.GA 'Stateless\.class$'
    /usr/local/jboss-4.0.5.GA/server/all/deploy/ejb3.deployer/jboss-ejb3x.jar: javax/ejb/Stateless.class
    /usr/local/jboss-4.0.5.GA/client/jboss-ejb3x.jar: javax/ejb/Stateless.class

By default, it only looks at files with the extensions 'jar', 'war', and
'ear'. Modify to suit...

HTH,
-Al


---------------------------------8<------------------------------------
#!/bin/sh

# -----------------------------------------------------------------------------
# Copyright (c) 2005 Alan D. Salewski
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, version 2.1.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
# -----------------------------------------------------------------------------

# findclass: Looks through all jar files beneath the specified location
# on the filesystem, and looks inside them to find a class that contains
# the regex pattern specified by the user.
#
# Prints that names of all jar files that contain a class whose name
# matches the specified pattern.
#
# FIXME: could be enhanced to look for all '*.class' files
#        beneath the current directory, too.
#
# FIXME: add support for regex modifiers or provide command line
#        switches to do case-insensitive matching, etc
#
# Example 1a: find Cofiguration.class \(loosely, may turn up classes
#             whose name ends with "Configuration.class", but is
#             simple to type\):
#     $ findclass . 'Configuration\.class$'
#
# Example 1b: find Cofiguration.class (strictly):
#     $ fileclass . '(?:^|\/)Configuration\.class$'
#
# Example 2: find classes where "Configuration" appears anywhere in
#            the package name:
#     $ fileclass . '.*Configuration.*'

declare -r PROG='findclass'

DIR_START="$1"; shift

CLAZZ_PATTERN="$1"

if test -z "$DIR_START" \
   || test -z "$CLAZZ_PATTERN"; then
    printf "usage: findclass <find_dir> <regex>\n" 1>&2
    exit 1
fi

if test -d "$DIR_START"; then :; else
    printf "${PROG} (error): \"${DIR_START}\" is not a directory\n" 1>&2
    exit 1
fi

for j in $(find "$DIR_START" -type f -a \( -name '*.jar' -o -name '*.war' -o -name '*.ear' \) -print); do
    perl -e '
        use strict;
        use warnings;
        my $jarfile = shift;
        my $match_pattern = shift;
        open (my $PIPELINE, "jar tf $jarfile |")
            or die "unable to open process for reading: $!";
        map { print "$jarfile: $_" }
            grep { m/$match_pattern/ }
            grep { m/\.class$/ }
            <$PIPELINE>;
        close ($PIPELINE) or warn "error while closing pipeline: $!";
    ' "$j" "$CLAZZ_PATTERN"
    if test $? -eq 0; then :; else
        printf "${PROG} (error): subprocess error, bailing out.\n" 1>&2
        exit 1
    fi
done
---------------------------------8<------------------------------------

-- 
:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
::
Alan D. Salewski
Software Developer
Health Market Science, Inc.
:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
:: 



More information about the jboss-user mailing list