Title: Programmatically Load Classes and Resources in a Deployment Describe the issue: A couple of minor problems. Suggestions for improvement: 1. Class targetClass = Class.forName("TargetClass", true, this.getClass().getClassLoader()); <-- should include a package name. 2. In "Load All Instances of a Single Resource", the text "use the Class.getClassLoader().getResources(String resourceName) method, where resource name is the fully qualified path the the resource" should be changed to "use the Class.getClassLoader().getResources(String resourceName) method, where *resourceName* is the fully qualified path *of* the resource" (emphasis added) ("resourceName" is a literal parameter name) 3. In "Load All Instances of a Single Resource" ... " returns an Enumeration of URL objects" is correct but the code sample then uses an incorrect construct (probably my fault, sorry) consisting of a URL[]. Change this code: URL[] urls = MyClass.class.getClassLoader().getResources("full/path/to/resource"); while (urls.hasMoreElements()) { URL url = urls.nextElement(); ... To: Enumeration<URL> urls = MyClass.class.getClassLoader().getResources("full/path/to/resource"); while (urls.hasMoreElements()) { URL url = urls.nextElement(); ... 4. The last section "Load a Class File From the Class Loader" is incorrect. Change this code: InputStream inputStream = TargetClass.class.getResourceAsStream(TargetClass.class.getSimpleName() + ".class"); To: InputStream inputStream = TargetClass.class.getResourceAsStream(TargetClass.class.getSimpleName().replace('.', '/') + ".class"); 5. In the "Load a Class File From the Class Loader" I also recommend changing this: InputStream inputStream = TargetClass.class.getClassLoader().getResourceAsStream("TargetClass".replace('.', '/') + ".class"); To: String className = "com.yourcompany.TargetClass"; InputStream inputStream = TargetClass.class.getClassLoader().getResourceAsStream(className.replace('.', '/') + ".class"); ...because in the given example the replacement is not necessary (the class name has no '.' in it), and in any case if you already have the class name it would be more logical to simply do the replacement by hand yielding "com/yourcompany/TargetClass.class" for example.
Good catches. Thanks! Made the changes to topic 24376.
Fix is staged here: http://documentation-devel.engineering.redhat.com/docs/en-US/JBoss_Enterprise_Application_Platform/6.2/html-single/Development_Guide/index.html#sect-Use_the_Class_Loader_Programmatically_in_a_Deployment
Verified. There is one more typo and I created new BZ for it. See https://bugzilla.redhat.com/show_bug.cgi?id=1030262