"Your time is limited, so don't waste it living someone else's life"

Get all sub-packages from a Class

A small code snippet to dictate how to get out all the sub package from a java class.

public static void getSubPackages(
        final List<String> lstSubPackages,
        final Class<?> anyClass) throws NullPointerException
        URL resource = anyClass.getResource("");
        if (resource != null)
            File processDir = new File(resource.getPath());
            File[] lstFiles = processDir.listFiles();
            if (lstFiles != null)
                for (File file : lstFiles)
                    if (file.isDirectory())

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: