mnaufaldillah

DynamicClassLoader Jmeter

Oct 23rd, 2021
547
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to you under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  * http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17.  
  18. package org.apache.jmeter;
  19.  
  20. import java.net.URL;
  21. import java.net.URLClassLoader;
  22. import java.net.URLStreamHandlerFactory;
  23.  
  24. /**
  25.  * This is a basic URL classloader for loading new resources
  26.  * dynamically.
  27.  *
  28.  * It allows public access to the addURL() method.
  29.  *
  30.  * It also adds a convenience method to update the current thread classloader
  31.  *
  32.  */
  33. public class DynamicClassLoader extends URLClassLoader {
  34.  
  35.     public DynamicClassLoader(URL[] urls) {
  36.         super(urls);
  37.     }
  38.  
  39.     public DynamicClassLoader(URL[] urls, ClassLoader parent) {
  40.         super(urls, parent);
  41.     }
  42.  
  43.     public DynamicClassLoader(URL[] urls, ClassLoader parent,
  44.             URLStreamHandlerFactory factory) {
  45.         super(urls, parent, factory);
  46.     }
  47.  
  48.     // Make the addURL method visible
  49.     @Override
  50.     public void addURL(URL url) {
  51.         super.addURL(url);
  52.     }
  53.  
  54.     /**
  55.      * Returns list of URLs to add to the thread's classloader.
  56.      * @param urls - list of URLs to add to the thread's classloader
  57.      */
  58.     public static void updateLoader(URL [] urls) {
  59.         DynamicClassLoader loader
  60.             = (DynamicClassLoader) Thread.currentThread().getContextClassLoader();
  61.         for(URL url : urls) {
  62.             loader.addURL(url);
  63.         }
  64.     }
  65. }
RAW Paste Data