Determining all classes available in the classpath

Hi,
I'm trying to recreate some functionality an ex-colleague of mine wrote some time ago!
Basically, he wrote (or found) some code that trawled through the whole classpath in order to discover all classes that were implemented a certain interface.
In that instance, this was used to check for all availible Datasource implementations so that we could "auto-detect" any new jdbc drivers that a customer may add to the classpath.
This solution is more for convenience - I've inherited a 900 file project and need to be able programmatically determine which of these are servlets.
Can't work out how to get a complete Class[] - I know how resolve the rest of the problem!
Thanks for any thoughts and suggestions.

You can use Javadoc API.
Write a small "doclet" that prints for each class of your project what interfaces it implements and from what class it derives, or simply tries to check (via instanceof) if the class implements javax.servlet.Servlet.
com.mycompany.legacy.MyServlet extends com.mycompany.legacy.MyFrameworkGenericServlet
com.mycompany.legacy.MyFrameworkGenericServlet extends javax.servlet.http.HttpServlet
javax.servlet.http.HttpServlet extends javax.servlet.GenericServlet
javax.servlet.GenericServlet implements javax.servlet.Servlet

Similar Messages

  • For all classes used in the alv reports.

    we need the list of required classes used in alv reports this urgent .
    please help me.

    Hi Navid,
    Check <b>SLIS Package/Dev.Class for node Classes</b>,
    here u will find all required <b>classes for ALV including ALV Hierarchical,AVL Tree, ALV HTML.</b>
    Classes.
    CL_ALVHT_HTMLINPUT-> ALV: HTML Input (Control Proxy)
    CL_ALVHT_HTML_PAGE-> ALV HTML Page
    CL_ALVHT_HTML_TEMPLATE-> ALV: HTML Templates
    CL_ALVHT_TAGSTREAM-> ALV
    CL_ALVHT_UI_ELEMENT-> ALV: HTML User Input Element
    CL_ALV_BDS-> BDS Access and Data Retention
    CL_ALV_CHANGED_DATA_PROTOCOL-> Message Log for Data Entry
    CL_ALV_DD_DOUBLE_LISTBOX-> Management Class for two D&D List Boxes
    CL_ALV_DD_LISTBOX-> D&D List Box
    CL_ALV_EVENT_DATA-> Changing Data Container for Events
    CL_ALV_EVENT_TOOLBAR_SET-> ALV Context Menu
    CL_ALV_GRAPHICS-> ALV Graphic (Integration with GFW)
    CL_ALV_GRAPHICS_CU-> Customizing of ALV Graphics
    CL_ALV_LISTBOX_DRAGOBJ->
    CL_ALV_OI BDS-> Access and Data Retention
    CL_ALV_TABLE_CREATE-> Dynamic Creation of ALV Data Table
    CL_ALV_TREE_BASE-> Basis Class ALV Tree Control
    CL_ALV_VARIANT-> ALV Variant Management
    CL_GUI_ALV_GRID-> ALV List Viewer
    CL_GUI_ALV_GRID_BASE-> Basis Class for ALV Grid
    CL_GUI_ALV_TREE-> ALV Tree Control
    Regards,
    Raghav
    Message was edited by:
            Raghavendra  L

  • Loading all classes on classpath

    Hello!
    I'm trying to create some kind of "Package browser" which I can use for selecting a class that exists on the classpath.
    I've come up with a solution that reads the classpath property and then looks up the classes by searching each directory and jar-file for class files. These are presented in a JTree. This solution has a drawback though. When using Visual Age for Java, my app won't find any class files on the classpath as these are not added to the local file system. It seems Visual Age has it's own ClassLoader which loads classes from it's own repository rather than from the file system.
    Now I wonder, is there another way to load all classes from the classpath?
    Regards,
    Pelle Poluha

    Visual Age uses the "system" classpath alright. When I add another directory to the classpath using VA, my "package browser" recognizes this but shows an empty directory. And it is empty on my local file system. What I can do is to export all the classes I need to a directory or jar-file and then add this to the classpath. Then my app recognizes the classes. But this is too cumbersome.
    What I need, I guess, is a way of communicating with the current classloader and get it to return all classes/packages in a given package. Anybody knows if that's possible?
    Regards,
    Pelle Poluha

  • Organizing class files (in the filesystem)

    Hi, I'm new to Java and the JDC. I have run into one issue, in my explorations in Java, and that is organizing the class files and source code files. I understand that I can organize them in any way that I like, but I was curious if there is a standard system that other Java developers use (like the /usr/local convention on Unix).
    Should I create a /usr/local/java directory and then store class and source files in subdirectories of that? And then add the class directory to the CLASSPATH? How about downloaded source code that I didn't write -- that seems like it would then go in yet another directory.
    So far I've got everything stored in ~/dev/java (a directory I created for this purpose), but it seems like it's bound to get unmanageable if I don't order it better. And I'm just curious what others with more experience do.
    Thanks!
    Erik

    Anyway, back to why. If as you mentioned you keep all of your class files off a given root folder, then you can add that folder root to the classpath.
    Okay, I have the domain "erikprice.com". So then I would create a hierarchy like this (?) :
    - ~
      - dev
        - Java
          - com
            - erikprice
              - packageA
              - packageB
              - packageC
                 ...etc...And then, if I add ~/dev/Java/com to my CLASSPATH, all of the classes in the various packages below that will be accessible to the compiler? Or do I have to explicitly put ~/dev/Java/com/erikprice into the classpath?
    Also, if I have downloaded someone else's source code (such as a Jakarta project or something), it seems like I should put its root folder in with my personal root folder. In other words, like this:
    - ~
      - dev
        - Java
          - com
            - erikprice
          - org
            - apache
              - xml
                - xerces
                  - packageA
                  - packageB
                - xalan
                  - packageA
                  - packageB
                  ...etc...Does this seem right? If I understand correctly, I will have to add the org directory to the CLASSPATH too. Can I save all of this trouble by putting just ~/dev/Java into the CLASSPATH so that all of the packages below (com/erikprice/*, org/apache/xml/*, org/someotherproject/*) are available?
    The trick of this is that I'm trying to organize both my own Java files as well as those that I've downloaded to study from. Thanks for your input, MLangstaff.

  • How to update the classpath on runtime

    My Application enables the user to select a directory. After this all *.class files in the directory and the subdirectories are listed. The User can now select a class to be initialised.
    This works well if the selected directory is in the Classpath. If the directory is not in the classpath, I tried to update the Classpath through
    System.setProperty("java.class.path",classpath).
    Well as I expected, this did not affect in any way. But how can I add the new directory to the classpath of the actual VM?
    Can anybody help please?

    Use a custom class loader. Examples have been posted in the forums. Search for them.

  • How to find out in program which all classes have implemented an interface

    Hello,
    I have created an interface and few classes are implementing the interface.
    I want to know in a program which all class have implemented the interface.
    Is it possible to find it out and how?
    Regards,
    Bikash.

    Hi Bikash,
    Read the Database view VSEOIMPLEM with where condition REFCLSNAME = Interface Name and version = 1.
    This would give you all the classes which have implemented the interface and are active...
    If you want to look at the values that the field version can have then see Type Group SEOC ans search for version....
    Hope this help...
    Regards,
    Sitakant

  • Making class available to bootstrap loader?  interesting twist.......

    We're deploying our jar wrapped in an exe (created by exe4j). It's not an option to unwrap the jar, but I want to make a particular class available to the bootstrap loader. If you're not familiar with exe4j, you can pass arguments to the jvm, so I can pass an -Xbootclasspath argument, but I have no idea how that works when the class is in a package in a jar in an exe. I've tried to pass arguments like -Xbootclasspath/a:com.organization.project.package.MyClass and of course it didn't work. Note that what I'm doing is security policy related, and I'd really prefer not to have this class outside of the wrapped jar.
    Is what I want to do actually possible? If so, what am I doing wrong?

    Erm, sorry for being unclear :s
    I'm doing my best to explain myself, please excuse me for not being a native english speaker ;)
    About showing more code, I wouldn't know which part to show : several classes are involved already, each of them weighing a couple hundred lines. That's why I prefer explaining rather than dropping unrevealing code snippets. :-x
    If from this description you know what piece of code interests you, I'll post it asap. Until then, here goes a shorter explanation of the situation.
    My custom ClassLoader loads .class entries from jar files using the java.util.jar package. I define those classes using defineClass(String name, byte[] b, int off, int len). At the same time entries from the jar file get processed, I list the classes which could or couldn't be loaded. The second list being empty once the jar is processed proved me the classes are well-loaded.
    Then I seek through the list of loaded ones for classes implementing AIPlayer, Player or other interfaces. My problem is that the classes implementing AIPlayer (c in my previous example) can't get assigned to AIPlayer though they can get assigned to Player, Player being a super-interface of AIPlayer.
    Additionnal information are : Player and AIPlayer are loaded by the bootstrap ClassLoader, the bootstrap ClassLoader being the parent of my custom ClassLoader's instance at some degree (it is either the parent or the parent of the parent).
    My question is : why can not a class implementing AIPlayer (and thus, Player) be assigned to AIPlayer, though it can be assigned to Player ?
    I hope I was clearer here. Thanks for lending me your time.

  • JAVABEAN ,is it all class need to collect together by package?

    hello,
    i want to know . all class stored in the class (C:\Tomcat_5.0\webapps\BB2004\WEB-INF\class\)in tomcat.
    is it must need to create folder to store all class. and package them in the folder.
    class A call the class B in the class A statement.
    class B , class A are stored in the same package.
    but class A cannot compile.
    how???
    in additional,
    in the jsp,
    if package name is test, so the class in following is it
    <jsp:useBean id="user1" scope="page" class="test.user"/>

    Class files get stored under the WEB-INF/classes folder, using the standard java layout.
    ie if class A is in package myPackage, then A.class should be in WEB-INF/classes/myPackage/A.class
    note that it is WEB-INF/classes, not WEB-INF/class
    Your useBean statement looks correct. Yes, you must specify the full classname of any bean you use (ie including package identifier)
    hope this helps

  • Using Reflection on classes outside the classpath

    Hi all,
    Im writing a tool that takes a directory containing class files (from other internal projects) and returns information such as the Class name, package, parent, constructors and public methods. These projects will not be on the classpath and will also use jars that are not on the classpath.
    I decided that ClassLoaders were the way to go. So I created a SimpleClassLoader class that takes a file, reads it in as an array of bytes and calls defineClass:
    public class SimpleClassLoader extends ClassLoader
         public SimpleClassLoader()
         public synchronized Class loadClass(String name, boolean resolveIt) throws ClassNotFoundException
              System.out.println("1) loading class:   " + name);
              return super.loadClass(name, resolveIt);
         public synchronized Class loadClass(File classFile) throws ClassNotFoundException
              System.out.println("2) Loading class: " + classFile.getName());
              try
                   byte[] data = getClassData(classFile);
                   return defineClass(name, data, 0, data.length);
              catch (IOException e)
                   throw new ClassNotFoundException();
         byte[] getClassData(File classFile) throws IOException
              byte result[];
              try
                   FileInputStream in = new FileInputStream(classFile);
                   result = new byte[in.available()];
                   in.read(result);
                   in.close();
                   return result;
              catch (IOException e)
                   throw new IOException();
    public class ClassParser
         public Class parse (File classFile)
              SimpleClassLoader loader = new SimpleClassLoader();
              Class reflectClass = null;
              try {
                   return loader.loadClass(classFile);
              } catch (ClassNotFoundException cnfe) {
                   System.out.println("Error loading class: " + classFile.getName() + "\n" + cnfe);
                   return null;
    }This worked for simple classes but when the superclass was in a jar or another file in the directory that hadnt already been loaded a ClassNotFoundException was thrown. So I then decided to try using URLClassLoader and loading in the jars and the entire source directory before calling findClass on it.
    class MyURLClassLoader extends URLClassLoader
         public MyURLClassLoader(URL[] urls)
              super(urls);
         public Class findClass(String classname) throws ClassNotFoundException
              return super.findClass(classname);
    public class ClassParser {
         private URL[] _classpath;
         private String _root;
         public ClassParser(File[] files, String root) {
              _root = root;
              _classpath = new URL[files.length];
              for (int i = 0; i < files.length; i++) {
                   try {
                        URL url = new URL("jar", "", files.toURL() + "!/");
                        this._classpath[i] = url;
                   } catch (MalformedURLException e) {
                        e.printStackTrace();
         public Class parse (File classFile)      {
              MyURLClassLoader urlLoader = new MyURLClassLoader(_classpath);
              Class reflectClass = null;
              String classname = "";
              // Try to load a Class instance from the file
              try {
                   classname = getClassName(classFile);
                   return urlLoader.findClass(classname);
              } catch (ClassNotFoundException cnfe) {
                   System.out.println("Error loading class: " + classname + "\n" + cnfe);
                   return null;
         String getClassName (File file) throws ClassNotFoundException {
              if (file.getAbsolutePath().startsWith(_root)) {
                   String packagePath = file.getAbsolutePath().substring(_root.length(), file.getAbsolutePath().lastIndexOf("."));
                   packagePath = packagePath.replace(File.separatorChar, '.');
                   return packagePath;
              } else {
                   throw new ClassNotFoundException();
         public static void main(String args[]) {
    File [] files = new File [] {
    new File("C:\\Projects\\app\lib\\jacob-1.6.jar"),
    new File("C:\\Projects\\app\\lib\\xalan.jar"),
    new File("C:\\Projects\\app\\lib\\xmlunit1.0.jar"),
    new File("C:\\Projects\\app\\classes\\com\\foo\\bar\\swing\\")
    parser = new ClassParser(files, "C:\\Projects\\app\\classes\\");
    This seems to work when I call findClass on a class thats in one of the jars but not on a class in the classes directory.
    Does anyone have any ideas what im doing wrong or whether im barking up the wrong tree completely??
    Thanks,
    Conor

    The URLs that you supply to an URLClassLoader each define the location of the default package for that portion of the classpath for the ClassLoader.
    This is the problem line
    new File("C:\\Projects\\app\\classes\\com\\foo\\bar\\swing\\")I suspect that it should be..
    new File( "C:\\Projects\\app\classes" )as this is the location of that default package.

  • How to set the classpath and path from the jsp to call  java class function

    Hi Exprets,
    I have a requirement to call a java class function which returns a hashmap object from the jsp. The java class in present in one jar file and that jar file is location somewhere in unix path. So the requirement is to set the classpath for that jar file and then create the object of the java class and then call the function.
    If any one know how to achieve it, please reply as soon as possible.
    thanks in advance,
    swapna soni.

    It is never advisable to store large data sets in the session. But it will depend on a lot of factors:
    1. How costly is the query retrieving the data from the database?
    If it's a complex query with lots of joins and stuff, then it will be better to store it in the session as processing the query each time will take a lot of time and will decrease performance. On the other hand if the query is simple then it's advisable not to store it in the session, and fetch it each time.
    2. Are there chances for the data to become stale within a session?
    In this case storing the data is session will mean holding the stale data till the user session lasts which is not right.
    3. How many data sets does the session already holds?
    If there are large no. of data sets already present in the session, then it's strictly not advisable to store the data in the session.
    4. Does the server employ some kind of caching mechanism?
    Using session cache can definitely improve performance.
    You will have to figure out, what is the best way analyzing all the factors and which would be best in the situation. As per my knowledge, session is the only place where session specific data can be stored.
    Also, another thing, if the data set retrieved is some kind of data to be displayed in reports, then it would be better to use a pagination query, which will retrieve only the specific no. of rows at a time. A navigation provided in the UI will retrieve the next/previous data set to display.
    Thanks,
    Shakti

  • JARs in WEB-INF/classes on the classpath? [NEWBIE]

    Hello,
    I am under the impression that any files (including JARs and all within
    them) are on the classpath if they are in the folder WEB-INF/classes.
    I have a WAR file that contains a JAR file that in the WEB-INF/classes
    folder. The JAR file contains a class under the package structure
    "mvc.users.Members". I know its there as I checked the WAR file structure
    before deploying.
    In the WAR file I have a Struts RegisterAction class in the package/folder
    "mvc.registration.RegisterAction" which has the following code to create a
    Member object:
    Member member = new Member();The Member class is imported into RegisterAction using
    import mvc.users.Members;and JBuilder appears to recognise Members as on the classpath and compiles
    with no errors.
    My problem is after I have deployed the WAR file, submitting a form to the
    RegisterAction gets the error below:
    javax.servlet.ServletException: Servlet execution threw an exception:
    root cause:
        java.lang.NoClassDefFoundError: mvc/users/Member
            mvc.registration.RegisterAction.execute(RegisterAction.java:22)
            org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
            org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
            org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
            org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:856)If the class "mvc.users.Member" is in the JAR file in the WEB-INF/classes
    folder and the "mvc.registration.RegisterAction" class in the WAR file
    does (according to JBuilder) see the "mvc.users.Member" class on the
    classpath and compiles... why then do I get this error?
    Thanks for your help.
    A Desperate Newbie,
    Mark

    I answered this in the JSP forum - you need to put JAR files in WEB-INF/lib.

  • Java.sql.Date and java.util.Date - class loaded first in the classpath

    I had two jar files which has java.util.Date and java.sql.Date class file. i want to know whether which class is loaded first in the classpath...
    I like to change the order of loading the class at runtime...
    Is there is any way to change the order of loading of class...
    I may have different version of jar files for example xerces,xercesImpl. some of the code uses xerces ,some of the code uses xercesImpl..i had common classes.
    I like to load the class with the same name according to the order i need..
    Can we do all these in Run time ?????

    I had two jar files which has java.util.Date and
    java.sql.Date class file. i want to know whether
    which class is loaded first in the classpath...
    I like to change the order of loading the class at
    runtime...
    Is there is any way to change the order of loading of
    class...
    I may have different version of jar files for example
    xerces,xercesImpl. some of the code uses xerces ,some
    of the code uses xercesImpl..i had common classes.
    I like to load the class with the same name according
    to the order i need..
    Can we do all these in Run time ?????That is meaningless.
    The classes you are referring to are part of the Java API. Third party jars have no impact on that. And you can't change to the order because java.sql.Data is derived from java.util.Date. So the second must load before the first.
    And if you have two jar files with those classes in them (and not classes that use them) then you either should already know how to use them or you should stop trying to do whatever you are doing because it isn't going to work.

  • Where to set the classpath for custom classes in jsp

    Hi,
    we have created our custom classes in and ported in contentDB and that classes are internally using some jar files. Previously we have set the classpath of all the jar files provided in CDB devkit in the orion-web.xml but if are opening the explorer.jsp or any other jspx of contentDB we are getting the classcastexception and page is not opening.
    Is there any problem in setting the classpath. Please if any one knows abt this, reply as soon as possible.
    thanks,
    swapna soni.

    I think it is Oracle 10g Release 2... since when I click the top OAS link in the Enterprise Manager Console, it took me to 'Enterprise Manager 10g Grid Control Release 2' this page.
    And...10g Application Server Control Release 10.1.2.0.1, I think 2.0.1 means Release 2.
    Thanks and let me know if you need something else.

  • Class file is referencing a type outside the classpath???

    Hi All,
    I'm developing a EJB project in NWDS.
    I'm getthing the below syntax error.
    This compilation unit indirectly references the missing type com.sap.exception.BaseException (typically some required class file is referencing a type outside the classpath)
    Can you please help me to resolve this?
    Thanks in advance.
    Sundar

    Hi Sundar,
    You need to add the ejb20.jar file to your Project classpath.
    If you are developing the project locally then the jar file can be directly added to the class path using the Project Properties --> Java build PAth --> Libraries tab --> Add External Jar.
    If it is a DC development, the ejb20.jar can be found under the SAP-JEE software component of your track.
    Hope it helps.
    Regards,
    Alka.

  • Getting the names of all classes

    Hi,
    I want to write a Java editor with code completion. Is there a way to get all the class names available in the installed Java run time environment.
    Does the reflection API provides a way to do it.
    Thanks a lot,
    Chamal.

    You can also look at JPDA (should be documented as part of your JDK under 'Tool Support' of the documents index), and the JDI api VirtualMachine.allClasses() method.
    That will return the name of all loaded classes, which will not be the same as all classes on the path, as it includes any dynamically created classes, and excludes any classes on the path not loaded.
    Pete

Maybe you are looking for

  • Problem with implemnting delete for each record in the report

    Hello all, I am having trouble implementing the following requirement in my application. In the reports, in each row..I need a delete button. Only few Users( Managers/Administrators) should be able to view this button. Rest should be able to see the

  • Getting Main Heading and Under that sub heading In ALV-Display

    Hi All,       I have a requirement to get ALV display with Main Headings and Under each Main heading there are Sub headings. The Output is somewhat like shown below       Costing view    |    MEQ1 View      VER. ID | Desc.    VER. ID | Desc. If some

  • Line and Iphone 3 (and IOS 4.2.1)

    hi, I have an Iphone3, with IOS 4.2.1. I had Line, and Line worked well. (last week!) Now, for Line, I need IOS 4.3. And IOS 4.3 doesn't work for Iphone 3. How could I use Line in my Iphone? Thanks for your help. arnaud

  • Old messages in My Folders (N6680) to N97

    How to transfer old messages from My Folder N6680 to N97? I can not see My Folders by PC Suit on N6680 but 97 is showing My folders Partial solutions: So I moved all messages from My Folders to Inbox then I exported to file (CSV). Then I imported to

  • Move components using mouse - drag and drop action?

    Hi, As attached, I want to move one component at the bottom to top using mouse in drag and drop action. But I don't know why it returns to the origianl position. it never move. Is there anyway I can change configuration to accomplish this?