Analyzing classes within a given .jar file

I want to write some code that will take a given .jar file and look through all of the classes defined within and pick out any classes that implement a couple of given interfaces. I've looked at the URLClassLoader class, but I don't really see how to get it to work. Anyone got any ideas?

I'm going to guess that your problem is getting a list of classes in the jar file in the first place. To do this, use classes and methods from the java.util.zip package and perhaps also the java.util.jar package.

Similar Messages

  • Taglib: class not found in jar-file

    I've got the following problem:
    I whant to deploy a taglib to tomcat 5.0.25.
    If I point to the jsp which uses the taglib I got the following error:
    org.apache.jasper.JasperException: Unable to read TLD "META-INF/taglib.tld" from JAR file "file:/C:/Programme/Apache Software Foundation/Tomcat 5.0/webapps/taglibtest/WEB-INF/lib/gsa_prod3_db_taglib.jar": org.apache.jasper.JasperException: Failed to load or instantiate TagExtraInfo class: ch.gsa.prodass3.taglib.TagAddAttributeTEI
    If I copy the taglib.tld out of the jar-file into WEB-INF and do the mapping in web.xml, I get this error:
    org.apache.jasper.JasperException: Failed to load or instantiate TagExtraInfo class: ch.gsa.prodass3.taglib.TagAddAttributeTEI
    root cause
    java.lang.ClassNotFoundException: ch.gsa.prodass3.taglib.TagAddAttributeTEI
    It seems like none of the files in the jar-file could be loaded.
    Has anybody an idea?
    Help would be very appreceated!
    Greetings, Jonas

    1 - double check the class is in the jar file, in that path, and is spelt correctly
    2 - restart Tomcat
    3 - check the contents of the tld file - particularly the extra-info tag and class name for it.

  • Overriding a class which is in JAR file ?

    Hi,
         I have an application which is a Java Applet that downloads JAR files in runtime. And this Java Applet is invoked from Internet Explorer through JInitiator 1.3.1.18. I want this application to use one class say "lwWin.class" which is in my local system instead of taking it from the JAR file. This class (lwWin.class) is in a package called "MyAwt.LwWins" of JAR files which are downloaded into the directory called "d:\Classes". Is it possible to let my application to use the class which is in local system instead of taking it from the JAR File ? Please tell me a way achieve this.Hope to see your replies soon.
    Thanks and Regards,
    Srinivas.

    It depends on the way the classes relate to one another. In a privilged appliction you could set up a special class loader, but the situation is somewhat complicated by the rules on how classes can reference those from other ClassLoaders.
    You could set up an extension of URLClassLoader that special-cases that specific class.

  • Including helper classes in java proxy jar file

    I must not be using the right header search criteria because I'm sure this question
    has been asked before. In a Web Service File (.jws) I've imported a couple of
    helper classes that function as data transfer objects. I did this to maintain
    consistency with other portions of the application. The Java Proxy jar file generated
    by Workshop does not include these files. Is there a way of including these dependencies
    or do I need to distribute another jar file with my helper classes?

    Hi Naichen,
    I was able to successfully run both the autotype and clientgen Ant task, on the
    WSDL you provided. The code behind those Ant tasks are pretty much what the WebLogic
    Web Services test page run. Are you using WLS 8.1 SP2? If not, you might want
    to try with that version.
    Regards,
    Mike Wooten
    "Naichen Liu" <[email protected]> wrote:
    >
    >
    >
    Hi,
    I am having a warning message when trying to generate java proxy jar
    file on weblogic8.1
    webservice test web app, the message is as follows:
    "Warning Failed to generate client proxy from WSDL definition for this
    service.
    Prescription Please verify the <types> section of the WSDL."
    in the mean time, on weblogic starting terminal, I saw the following
    exceptions,
    C:\DOCUME~1\u252738\LOCALS~1\Temp\wlwproxy37508.jar1533409921\com\ual\www\rcc\cb
    t\schema\modifypnr\AlphaLength4Deserializer.java:36: cannot resolve symbol
    symbol : class FacetUtils
    location: package binding
    weblogic.xml.schema.binding.FacetUtils.checkLengthFacet(__typed_obj,4L);
    ^
    C:\DOCUME~1\u252738\LOCALS~1\Temp\wlwproxy37508.jar1533409921\com\ual\www\rcc\cb
    t\schema\modifypnr\OSIFieldAnonTypeDeserializer.java:36: cannot resolve
    symbol
    symbol : class FacetUtils
    location: package binding
    weblogic.xml.schema.binding.FacetUtils.checkMaxLengthFacet(__typed_obj,69L);
    ^
    C:\DOCUME~1\u252738\LOCALS~1\Temp\wlwproxy37508.jar1533409921\com\ual\www\rcc\cb
    t\schema\modifypnr\AlphaLength2Deserializer.java:36: cannot resolve symbol
    symbol : class FacetUtils
    location: package binding
    weblogic.xml.schema.binding.FacetUtils.checkLengthFacet(__typed_obj,2L);
    ^
    C:\DOCUME~1\u252738\LOCALS~1\Temp\wlwproxy37508.jar1533409921\com\ual\www\rcc\cb
    t\schema\modifypnr\FreeFormAnonTypeDeserializer.java:36: cannot resolve
    symbol
    symbol : class FacetUtils"
    Can anybody help me about this issue? I attached WSDL file, also United
    Airlines
    got an enterprise weblogic license deal with BEA, any help will be highly
    appreciated.
    Thanks!!!
    Naichen

  • Unable to access classes in third party jar files packaged with my ejb.jar

    I have packaged some third party jar files in my xxx_ejb.jar file.  The third party jar file contains classes that are accessed by some custom classes which are in turn accessed by my bean classes.  I get the following error when my custom classes attempt to use any of the classes in one of the third party jar files:
    java.lang.NoClassDefFoundError: com/Ostermiller/util/CSVParser
    Shouldn't I be able to access classes in jar files that are packaged with my xxx_ejb.jar file?  I see the xxx_ejb.jar file as a resource of the application classloader that contains it but I don't see the third party jar files.

    As per the Java EE specification, additional JAR files should be packaged on the EAR level. Only WAR files' WEB-INF/lib folder is scanned for JAR files to be added to the classloader.

  • Multiple Class-Path: attributes in Jar files

    Hello,
    I'm packaging a set of jar files for distribution with Class-Path: attributes in them. In the documentation I read and in one of the java trails it said that I could have a manifest file like:
    Class-Path: log4j.jar log4j-core.jar
    Class-Path: jsse.jar jcert.jar jnet.jar
    But this doesn't work. It only works when I do this:
    Class-Path: log4j.jar log4j-core.jar jsse.jar jcert.jar jnet.jar
    Here is how I'm running the jar:
    java -jar server.jar
    Is the documentation wrong? Or this is a bug?
    thanks
    charlie

    Certain attributes were only meant to be specified once. Like Main-Class and Class-Path for example. If these were listed two or more times, then the last occurance is the one that gets recognized (basically, each new instance overwrites the previous instance). Some attributes are listed as "per-entry" and are freely duplicated for each entry. For example signed jars could have a number of Name: and xxx-Digest: attributes.
    This link is to the manifest spec:
    http://java.sun.com/products/jdk/1.2/docs/guide/jar/manifest.html
    To answer the original posters question, the doc's are in error. Actually, the error was not in the docs, it was in the tutorial, but none the less its still in error. He could have done this:
    Class-Path: log4j.jar log4j-core.jar
    jsse.jar jcert.jar jnet.jar
    ^-- two spaces before the start of jsse.jar
    because the docs allow for line continuation (although it's not exactly clear if you read the docs). The docs are also apparently in error regarding the max line length of 72 bytes. I have tested this with over 100 char's on a win32 machine and it works fine for me. The limitation must therefore apply to some other operating system, or it could just be in error.
    -Ron

  • How to search a class in list of  jar files

    Hi All,
    I am using Windows XP. I have some 100's of jars and I want to find in which jar file a particular class exists. The search option in Windows XP (except Windows 2000) doesn't help. I tried the sourceforge.net jarbrowser tool but it's search functionality is not working.
    Can anybody please suggest a nice tool or approach ...
    Thanks & Regards,
    Kr.

    I know of one named ClassFinder that will do what you want.

  • Failed to load main-class manifest attribute from jar files....

    Hi,
    I installed Java1.5 version in my system before to that Java1.6 was installed and uninstalled. When i i double clicked on any jar file getting a message like: Failed to load main-class manifest attribute from<name of the jar file>.jar file....
    can anyone please suggest me how to rectify this error.

    mvnath wrote:
    The jar files are worked before the installation of 1.5 but not after installation of 1.5I am guessing that the Windows file association for .jar somehow got munjed. It's hard to say since you have not provided much information.

  • Finding class inside of the jar file...

    Hi,
    please could someone explain me, what is the difference between this object mapping...
    env->FindClass("com/dir1/dir2/ClassA");
    and
    env->FindClass("Lcom/dir1/dir2/ClassA;");
    because if class 'ClassA' resides inside of the jar file, which is appended to the classpath, Lcom/dir1/dir2/ClassA; don't succed and FindClass returns NULL!!!!
    Instead of if i use 'com/dir1/dir2/ClassA' string FindClass method ends with success....
    But i don't understand this...i was wondering that all my objects, not default java objects, should be mapped as L<class>;....:-((
    Please heellp

    I have noticed that a class have several notations which have been brough together of late. Even ObjectOutputStream write both java.lang.String and java/lang/String, arrays appear as [Ljava.lang.String; and the code will decode Ljava.lang.String; correctly even though it will not get generated.
    It is possible that this historical discrepencies are more visable at the native level and are yet to be fixed up ????                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Is web-inf/classes like a exploded jar file?

    ie, can it make sense to have an ejb-jar.xml in the web-inf/classes directory of a war file?
    Petstore has one!
    Thanks
    Martin

    Unless I'm mistaken, yes, you could think of it this way.
    In development, I usually compile things to WEB-INF/classes (and put .xml and .properties files there too) and when everything works, make a .jar of it.
    Hope this helps.
    Patrick

  • How do class paths work with JAR files?

    Hey all,
    I have in the manifest file a path to a folder, plugins. In it I have a dir and files myDir/*.* so when unzipped it has <install-dir>/plugins/myDir/*.*. In the MF file I indicate the plugins dir as part of the class-path. When I want to load a .class file from the myDir/ dir below plugins, and the classes in there do NOT have package names in them, how is that done? Every time I try to access a file via Class.forName() it says ClassNotFoundException. If I hard-code the string as "myDir/myplugin" or use package identifer "myDir.myplugin" it still doesn't work. I don't want to unzip a ton of files from each plugin in one dir. I want a more organized way of storing them. However, because plugins can be added after the file is unzipped, I can't specify all the locations of plugins/<dir> dir's in the MF file if more are added later. Is there a way to locate and load a class in ANY dir, even those that are NOT in the class-path? Please help me out if you know. Thanks.

    I really can't help accept to say that it is the way it is to avoid naming conflicts i think. can you make the plugins packages ? Otherwise especially if various people write them there may be some crazy naming conflicts hidden in trying to load things from anyplace.

  • Access JAR File while running App with Java Web Start

    Hello guys,
    I want to delpoy my application so that I can run it when I click on the appropriate button in a web page.
    I have a Jar file for all the files that the app needs. No, not all of the files are included.
    Indeed, I use JAR files such jdom.jar or postgres...jar that I must use in within my application.
    How can I access these JAR files knowing that I can't point to files in a JAR file A from within a JAR file B, if the JAR file B contains the JAR file A?
    The main JAR file that I put on the web server can be seen as the JAR file B and the other JAR files must be stored somewhere for the java classes within the main JAR file to have access to them.
    I wonder whether there is another way to structure the project.
    Thanks.

    Hi Andrew.
    I have followed your suggestions and here is what my .jnlp file look like:
    <tt>
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0+" codebase="http://localhost:8080/koedops" href="beta.jnlp">
         <information>
              <title>KOEDOPS</title>
              <vendor>Pr. Fischer</vendor>
              <homepage href="http://localhost:8080/" />
              <description>Downloading koedops with Java Web Start</description>
         </information>
         <resources>
              <j2se version="1.6+" />
              <jar href="beta.jar" main="true"/>
              <jar href="jcalendar-1.3.3.jar" />
              <jar href="jdom.jar" />
              <jar href="postgresql-8.4-701.jdbc4.jar" />
         </resources>
         <application-desc main-class="general.Application" />
    </jnlp>               
    </tt>
    The three other jar-files reside in the same directory as the .jnlp file and the beta.jar file on the tomcat server.
    When I launch the application though nothing happens upon the download. In contrast, if I change the main class to a class file that requires no extra library, it runs perfectly.
    I can't be sure whether the jar-files are successfully accessed.
    Regards.
    Edmond

  • Common classes across separate EJB jars

    What is the best way to package classes that are common across separate EJB jar files? IE, i have an object that is passed between the 2, or a utility that is used by both. Is it customary to package the classes within the EJB jar file? This seems silly to me because
    now you have 2 versions of the same class that could possibly change in one of them. Or should I put the classes into the classpath of the J2EE container? Thanks for any advice.

    Both ways will work, we prefer the first one (packaging the classes in both jars). We are using BEA WebLogic 6.x and putting it in the containers classpath would mean to restart the server every time we changed this classes. Mabe you should consider making a single jar for both EJBs if they will always be used together.
    Regards,
    hedtfeld.

  • Locating classes given many JAR files

    This may seem a basic thing, but I'm having trouble figuring out how people locate the correct JAR file to include when given just the package and class name.
    In searching for a solution to a problem I'd come across web document that tell me all about a particular class or set of classes that will solve this or that problem. The document goes on to give me the package name that the class(es) belong to. The problem is, these classes are in a JAR file and the document doesn't tell me the name of the JAR file or where to get it - assuming I don't have it.
    Assuming I do have the JAR file, that JAR file is usually in a directory with many more JAR files (for example, WSAD includes a whole bunch of JAR files or me). What's the best way to locate the package and/or class file(s) within all these JAR files? Why don't authors tell us the name of the JAR file these class(es) are in? Does anyone else have this problem besides me?

    Haven't tried. But still worth having a look into this free plug-in for Eclipse.
    http://www.icewalkers.com/Linux/Software/520170/JAR-Class-Finder.html
    Thanks
    Venkat

  • Class Loader for Jar Files

    I have a set of Jar files which i need to load using Custom Class Loader. Any one who has Javacode for Custom Class Loader for loading Jar files send it. The Jar files are local jar files.

    Here is the class loader I use:
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.net.JarURLConnection;
    import java.lang.reflect.Method;
    import java.lang.reflect.Modifier;
    import java.lang.reflect.InvocationTargetException;
    import java.util.jar.Attributes;
    import java.io.IOException;
    * A class loader for loading jar files, both local and remote.
    public class JarClassLoader extends URLClassLoader {
        private URL url;
        private URL[] m_urlList = new URL[10];
         * Creates a new JarClassLoader for the specified url.
         * @param url the url of the jar file
        public JarClassLoader(URL url,ClassLoader cl) {
             super(new URL[] { url },cl);
          this.url = url;
        public JarClassLoader(URL[] urlList,ClassLoader cl) {
             super( urlList,cl);
          this.m_urlList = urlList;
         * Returns the name of the jar file main class, or null if
         * no "Main-Class" manifest attributes was defined.
        public String getMainClassName() throws IOException {
          URL u = new URL("jar", "", url + "!/");
             JarURLConnection uc = (JarURLConnection)u.openConnection();
             Attributes attr = uc.getMainAttributes();
             return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null;
         * Invokes the application in this jar file given the name of the
         * main class and an array of arguments. The class must define a
         * static method "main" which takes an array of String arguemtns
         * and is of return type "void".
         * @param name the name of the main class
         * @param args the arguments for the application
         * @exception ClassNotFoundException if the specified class could not
         *            be found
         * @exception NoSuchMethodException if the specified class does not
         *            contain a "main" method
         * @exception InvocationTargetException if the application raised an
         *            exception
         public void invokeClass(String name, String[] args) throws ClassNotFoundException,
                NoSuchMethodException,
                InvocationTargetException
             Class c = loadClass(name);
             Method m = c.getMethod("main", new Class[] { args.getClass() });
             m.setAccessible(true);
             int mods = m.getModifiers();
             if (m.getReturnType() != void.class || !Modifier.isStatic(mods) || !Modifier.isPublic(mods)) {
             throw new NoSuchMethodException("main");
             try {
               m.invoke(null, new Object[] { args });
             } catch (IllegalAccessException e) {
             // This should not happen, as we have disabled access checks
    }

Maybe you are looking for

  • Migration set up two accounts. How do I share them?

    Hello, Just bought my first Mac. I used migration assistant to transfer things. First I transferred all my folders, files, and photos. Then later, overnight, I transferred all my music. It appears that Migration Assistant has now set up two "users" f

  • Connection to DB w/ Dreamweaver and GoDaddy

    I'm taking a Dreamweaver class right now. It tells me to setup a database on my server. On GoDaddy I got to databases, go to access (that is what I'm using) and create a DSN.. I name it the same as my database and it names it "access_mydatabasename"

  • How to view hidden user files and reset permissions

    I am having difficulties getting the hidden files to appear first of all. I have tried a couple of different things that have been suggested in other posts. And I would really like a point in the right direction to find information on resetting permi

  • ITunes setup won't launch on windows 8

    I finally got to download iTunes on my new Gateway laptop with Windows 8, but when I open the setup wizard (or try to) it tells me I have to find a version that runs for my PC. This is really mgetting me frustrated so can someone please help me out?

  • How to report to SAP..

    Hello I have seen this messag ewhile troubleshooting j2ee engine. If the problem persists, or you are unable to identify the cause of the problem, create a CSS message. Create the CSS message under the component BC-JAS-COR and short text "Bootstrap e