哦,这个问题,在d:\test\demo\Hello.class这里面的包,你根本就获取不了class文件,必须是要放在WEB-INF中的classes文件中,jar文件,就要放在WEB-INF\lib中了,这样的话,你才能在你的web中,把那个<%@ page import demo.Hello %>才能取道的

解决方案 »

  1.   

    事实上,如果将class即所在的包结构压缩成jar文件,在选取它,获得其包结构是很轻松,可问题有来了,这是class里的public方法不好获得啊,大家继续努力吧!
      

  2.   

    java.lang.Class & java.lang.reflect.Method
      

  3.   

    getPackage
    public Package getPackage()Gets the package for this class. The class loader of this class is used to find the package. If the class was loaded by the bootstrap class loader the set of packages loaded from CLASSPATH is searched to find the package of the class. Null is returned if no package object was created by the class loader of this class. 
    Packages have attributes for versions and specifications only if the information was defined in the manifests that accompany the classes, and if the class loader created the package instance with the attributes from the manifest. 
    Returns:
    the package of the class, or null if no package information is available from the archive or codebase.
      

  4.   

    getMethods
    public Method[] getMethods()
                        throws SecurityExceptionReturns an array containing Method objects reflecting all the public member methods of the class or interface represented by this Class object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if this Class object represents a class or interface that has no public member methods, or if this Class object represents an array class, primitive type, or void. 
    If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.PUBLIC as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException. The class initialization method <clinit> is not included in the returned array. If the class declares multiple public member methods with the same parameter types, they are all included in the returned array. See The Java Language Specification, sections 8.2 and 8.4. 
      

  5.   

    上面的弟兄提供的资料很好,谢谢!
    也就是说所操作的类必须是classpath下对吧,如果是某个路径下的class,事先我并没有将它放在classpath下,这时候要获得那个class的包结构和public方法又该怎么办呢?