Java Class Exist classExists(ClassLoader loader, String className)

Here you can find the source of classExists(ClassLoader loader, String className)

Description

Check if a classloader has a classname resource.

License

Apache License

Parameter

Parameter Description
loader the classloader to look it.
className the name of the class to look for.

Return

true if the classexists, false otherwise

Declaration

public static boolean classExists(ClassLoader loader, String className) 

Method Source Code

//package com.java2s;
/*/*  w ww . ja  v a 2  s . co m*/
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

public class Main {
    /**
     * Check if a classloader has a classname resource.
     * @param loader the classloader to look it.
     * @param className the name of the class to look for.
     * @return true if the classexists, false otherwise
     * @since Ant 1.7.0.
     */
    public static boolean classExists(ClassLoader loader, String className) {
        return loader.getResource(classNameToResource(className)) != null;
    }

    /**
     * Return the resource name of a class name.
     * @param className the name of the class to convert.
     * @return the corresponding resource name.
     * @since Ant 1.7.0.
     */
    public static String classNameToResource(String className) {
        return className.replace('.', '/') + ".class";
    }
}

Related

  1. classExists(String className)
  2. classExists(String className)
  3. classExists(String className)
  4. classExists(String className, Object context)