Jar Class Loader : ClassLoader « Reflection « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Reflection » ClassLoaderScreenshots 
Jar Class Loader
      
/*
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 
 * - Redistribution in binary form must reproduce the above
 *   copyright notice, this list of conditions and the following
 *   disclaimer in the documentation and/or other materials
 *   provided with the distribution.
 
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 
 * This software is provided "AS IS," without a warranty of any
 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
 * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
 * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
 * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
 * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
 * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
 * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 
 * You acknowledge that this software is not designed, licensed or
 * intended for use in the design, construction, operation or
 * maintenance of any nuclear facility.
 */

import java.io.IOException;

import java.net.URL;
import java.net.URLClassLoader;

import java.util.jar.Attributes;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * A class loader for loading jar files, both local and remote.
 * Adapted from the Java Tutorial.
 *
 * http://java.sun.com/docs/books/tutorial/jar/api/index.html
 
 @version 1.3 02/27/02
 @author Mark Davidson
 */
public class JarClassLoader extends URLClassLoader {

    // These manifest attributes were left out of Attributes.Name
    // They have to go somewhere so the chaces are if you need them,
    // then you are playing with this class loader.
    public static final Attributes.Name Attributes_Name_JAVA_BEAN = new Attributes.Name("Java-Bean");
    public static final Attributes.Name Attributes_Name_NAME = new Attributes.Name("Name");

    private static JarClassLoader loader = null;
    
    /** 
     * Null ctor DO NOT USE. This will result in an NPE if the class loader is
     * used. So this class loader isn't really Bean like.
     */
    public JarClassLoader()  {
        this(null);
    }

    /**
     * Creates a new JarClassLoader for the specified url.
     *
     @param url The url of the jar file i.e. http://www.xxx.yyy/jarfile.jar
     *            or file:c:\foo\lib\testbeans.jar
     */
    public JarClassLoader(URL url) {
        super(new URL[] { url });
    }
    
    /** 
     * Adds the jar file with the following url into the class loader. This can be 
     * a local or network resource.
     
     @param url The url of the jar file i.e. http://www.xxx.yyy/jarfile.jar
     *            or file:c:\foo\lib\testbeans.jar
     */
    public void addJarFile(URL url)  {
        addURL(url);
    }

    /** 
     * Adds a jar file from the filesystems into the jar loader list.
     
     @param jarfile The full path to the jar file.
     */
    public void addJarFile(String jarfile)  {
        try {
            URL url = new URL("file:" + jarfile);
            addURL(url);
        catch (IOException ex) {
            Logger.getAnonymousLogger().log(Level.WARNING, "Error adding jar file", ex);
        }
    }
    
    //
    // Static methods for handling the shared instance of the JarClassLoader.
    //

    /** 
     * Returns the shared instance of the class loader.
     */
    public static JarClassLoader getJarClassLoader()  {
        return loader;
    }
    
    /** 
     * Sets the static instance of the class loader.
     */
    public static void setJarClassLoader(JarClassLoader cl)  {
        loader = cl;
    }
}

   
    
    
    
    
    
  
Related examples in the same category
1. Determining from Where a Class Was Loaded
2. Loading a Class That Is Not on the Classpath
3. Dynamically Reloading a Modified Class
4. Get the path from where a class is loaded
5. Using the forName() method
6. Unqualified names
7. Return the context classloader.
8. Zip Class Loader
9. Load class from Thread's ContextClassLoader, classloader of derived class or the system ClassLoader
10. Various Class Loader utilities
11. Load Class
12. Load classes
13. Class Finder
14. Class For Name
15. Context ClassLoader
16. Analyze ClassLoader hierarchy for any given object or class loader
17. A class loader which loads classes using a searchlist of other classloaders
18. Equivalently to invoking Thread.currentThread().getContextClassLoader().loadClass(className); but it supports primitive types and array classes of object types or primitive types.
19. A class to simplify access to resources through the classloader
20. Get a compatible constructor for the given value type
21. Force the given class to be loaded fully.
22. does Class Exist
23. Java interpreter replacement
24. Utility to essentially do Class forName and allow configurable Classloaders.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.