Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/URLClassLoader/GetURLsTest.java
38811 views
/*1* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.net.*;24import java.io.*;2526/*27* Regression test for URLClassLoader getURLs() and addURL() methods.28* See RFE 4102580: Need URLClassLoader.getURLs() method29*/30class GetURLsTest {31public static void main(String[] args) throws Exception {32MyURLClassLoader ucl =33new MyURLClassLoader(new URL[] { new File(".").toURL() });34p("initial urls = ", ucl.getURLs());35URL u = ucl.getResource("GetURLsTest.java");36if (u != null) {37p("found resource = " + u);38}39ucl.addURL(new File("jars", "class_path_test.jar").toURL());40p("new urls = ", ucl.getURLs());41Class c = ucl.loadClass("Foo");42p("found class = " + c);43}4445static class MyURLClassLoader extends URLClassLoader {46public MyURLClassLoader(URL[] urls) {47super(urls);48}49public void addURL(URL url) {50super.addURL(url);51}52}5354static void p(String s, URL[] urls) {55System.out.print(s);56if (urls.length > 0) {57for (int i = 0; i < urls.length - 1; i++) {58System.out.print(urls[i] + " ");59}60}61System.out.println(urls[urls.length - 1]);62}6364static void p(String s) {65System.out.println(s);66}67}686970