Java Utililty Methods Jar Usage

List of utility methods to do Jar Usage

Description

The list of methods to do Jar Usage are organized into topic(s).

Method

ListgetClassNameByJar(String jarPath, boolean childPackage)
get Class Name By Jar
List<String> myClassName = new ArrayList<String>();
String[] jarInfo = jarPath.split("!");
String jarFilePath = jarInfo[0].substring(jarInfo[0].indexOf("/"));
String packagePath = jarInfo[1].substring(1);
try {
    JarFile jarFile = new JarFile(jarFilePath);
    Enumeration<JarEntry> entrys = jarFile.entries();
    while (entrys.hasMoreElements()) {
...
String[]getEntriesName(String jarFileName)
Util: gets the name of the entries from the given jar file name
JarFile jarFile = new JarFile(jarFileName);
String[] tabEntriesName = null;
int nbEntries = jarFile.size();
if (nbEntries > 0) {
    Enumeration jarEntries = jarFile.entries();
    tabEntriesName = new String[nbEntries];
    JarEntry currentJarEntry = null;
    int i = 0;
...
String[]getFileNamesWithSuffixForJarFile(JarFile jar, String suffix)
Convenience method to return the names of files specified in the jar file that end with the specified suffix.
Enumeration jarEntries = jar.entries();
Set<String> files = new HashSet();
while (jarEntries.hasMoreElements()) {
    String entry = ((JarEntry) jarEntries.nextElement()).getName();
    if (entry.endsWith(suffix)) {
        files.add(entry);
return files.toArray(new String[files.size()]);
voidgetInfo(String jarFileName)
Util: gets information about the given jar file name
JarFile jarFile = new JarFile(jarFileName);
System.out.println("\n---------------------------------------------------------");
System.out.println("Information about the jar file: " + jarFileName);
System.out.println("---------------------------------------------------------");
Enumeration jarEntries = jarFile.entries();
JarEntry currentJarEntry = null;
while (jarEntries.hasMoreElements()) {
    currentJarEntry = (JarEntry) jarEntries.nextElement();
...
ListgetJarInFileList(JarFile jarFile, String targetPath)
get Jar In File List
List<String> list = new ArrayList<String>();
for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) {
    JarEntry entry = e.nextElement();
    String name = entry.getName();
    if (name.startsWith(targetPath)) {
        list.add(name);
return list;
ListgetMatchingResourcesFromJar(JarFile jarFile, String suffix)
Retrieve all resources with the specified suffix in the jar.
List<String> result = new ArrayList<String>();
Enumeration<JarEntry> entries = jarFile.entries(); 
while (entries.hasMoreElements()) {
    JarEntry entry = entries.nextElement();
    if (suffix == null || entry.getName().endsWith(suffix))
        result.add("/" + entry.getName());
return result;
...
MapgetSortedAttributes(Attributes mainAttributes)
get Sorted Attributes
Map<String, String> sortedMainAttributes = new TreeMap<String, String>();
for (Map.Entry<Object, Object> attributeEntry : mainAttributes.entrySet()) {
    Attributes.Name attributeName = (Attributes.Name) attributeEntry.getKey();
    sortedMainAttributes.put(attributeName.toString(), (String) attributeEntry.getValue());
return sortedMainAttributes;
JarEntry[]getSortedJarEntries(JarFile jarFile)
get Sorted Jar Entries
Enumeration<JarEntry> e = jarFile.entries();
ArrayList<JarEntry> list = new ArrayList<JarEntry>();
while (e.hasMoreElements()) {
    JarEntry jarEntry = e.nextElement();
    list.add(jarEntry);
JarEntry[] sortedJarEntries = new JarEntry[list.size()];
int outerClassInd = 0;
...
booleanisSet(Attributes attributes, String name)
is Set
boolean isSet = false;
String s = attributes.getValue(name);
if (s != null) {
    s = s.trim();
    isSet = s.equalsIgnoreCase("true");
return isSet;
SetlistFiles(JarFile jarFile, String path)
list Files
final Enumeration<JarEntry> entries = jarFile.entries();
final Set<String> result = new TreeSet<String>();
while (entries.hasMoreElements()) {
    final String name = entries.nextElement().getName();
    if (name.startsWith(path)) {
        result.add(name.substring(path.length()));
return result;