<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FReflection%2FClassPath</id>
		<title>Java Tutorial/Reflection/ClassPath - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FReflection%2FClassPath"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Reflection/ClassPath&amp;action=history"/>
		<updated>2026-04-22T01:28:42Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Reflection/ClassPath&amp;diff=2973&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Reflection/ClassPath&amp;diff=2973&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:26Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:44, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Reflection/ClassPath&amp;diff=2974&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Reflection/ClassPath&amp;diff=2974&amp;oldid=prev"/>
				<updated>2010-05-31T15:19:37Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Get the path from where a class is loaded ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Main csl = new Main();&lt;br /&gt;
    csl.getCodeSourceLocation();&lt;br /&gt;
  }&lt;br /&gt;
  private void getCodeSourceLocation() {&lt;br /&gt;
    System.out.println(&amp;quot;Code source location: &amp;quot;&lt;br /&gt;
        + getClass().getProtectionDomain().getCodeSource().getLocation());&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Loading a Class That Is Not on the Classpath ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
A URLClassLoader can be used to load classes in any directory.&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.net.URL;&lt;br /&gt;
import java.net.URLClassLoader;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    File file = new File(&amp;quot;c:\\&amp;quot;);&lt;br /&gt;
    URL url = file.toURI().toURL(); &lt;br /&gt;
    URL[] urls = new URL[] { url };&lt;br /&gt;
    ClassLoader cl = new URLClassLoader(urls);&lt;br /&gt;
    Class cls = cl.loadClass(&amp;quot;com.mycompany.MyClass&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Load the class source location from Class.getResource() ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    Class theClass = Main.class;&lt;br /&gt;
    java.net.URL u = theClass.getResource(&amp;quot;&amp;quot;);&lt;br /&gt;
    System.out.println(&amp;quot;This class (FromWhere) is located at : &amp;quot; + u);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Obtain from where a Class is loaded ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    Main m = new Main();&lt;br /&gt;
    System.out.println(m.getClass().getName() + &amp;quot; is loaded from &amp;quot;&lt;br /&gt;
        + m.getClass().getProtectionDomain().getCodeSource().getLocation());&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Returns a reference to a file with the specified name that is located somewhere on the classpath. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
 * JCommon : a free general purpose class library for the Java(tm) platform&lt;br /&gt;
 * &lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.&lt;br /&gt;
 * &lt;br /&gt;
 * Project Info:  http://www.jfree.org/jcommon/index.html&lt;br /&gt;
 *&lt;br /&gt;
 * This library is free software; you can redistribute it and/or modify it &lt;br /&gt;
 * under the terms of the GNU Lesser General Public License as published by &lt;br /&gt;
 * the Free Software Foundation; either version 2.1 of the License, or &lt;br /&gt;
 * (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This library is distributed in the hope that it will be useful, but &lt;br /&gt;
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY &lt;br /&gt;
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public &lt;br /&gt;
 * License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
 * License along with this library; if not, write to the Free Software&lt;br /&gt;
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, &lt;br /&gt;
 * USA.  &lt;br /&gt;
 *&lt;br /&gt;
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. &lt;br /&gt;
 * in the United States and other countries.]&lt;br /&gt;
 * &lt;br /&gt;
 * ------------------&lt;br /&gt;
 * FileUtilities.java&lt;br /&gt;
 * ------------------&lt;br /&gt;
 * (C) Copyright 2000-2004, by Object Refinery Limited.&lt;br /&gt;
 *&lt;br /&gt;
 * Original Author:  David Gilbert (for Object Refinery Limited);&lt;br /&gt;
 * Contributor(s):   -;&lt;br /&gt;
 *&lt;br /&gt;
 * $Id: FileUtilities.java,v 1.5 2005/10/18 13:16:02 mungady Exp $&lt;br /&gt;
 *&lt;br /&gt;
 * Changes (from 5-Nov-2001)&lt;br /&gt;
 * -------------------------&lt;br /&gt;
 * 05-Nov-2001 : Changed package to com.jrefinery.io.* (DG);&lt;br /&gt;
 * 04-Mar-2002 : Renamed Files.java --&amp;gt; FileUtilities.java (DG);&lt;br /&gt;
 * 10-Oct-2002 : Fixed errors reported by Checkstyle (DG);&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.util.StringTokenizer;&lt;br /&gt;
/**&lt;br /&gt;
 * A class containing useful utility methods relating to files.&lt;br /&gt;
 * &lt;br /&gt;
 * @author David Gilbert&lt;br /&gt;
 */&lt;br /&gt;
public class FileUtilities {&lt;br /&gt;
  /**&lt;br /&gt;
   * Returns a reference to a file with the specified name that is located&lt;br /&gt;
   * somewhere on the classpath. The code for this method is an adaptation of&lt;br /&gt;
   * code supplied by Dave Postill.&lt;br /&gt;
   * &lt;br /&gt;
   * @param name&lt;br /&gt;
   *          the filename.&lt;br /&gt;
   * &lt;br /&gt;
   * @return a reference to a file or &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt; if no file could be&lt;br /&gt;
   *         found.&lt;br /&gt;
   */&lt;br /&gt;
  public static File findFileOnClassPath(final String name) {&lt;br /&gt;
    final String classpath = System.getProperty(&amp;quot;java.class.path&amp;quot;);&lt;br /&gt;
    final String pathSeparator = System.getProperty(&amp;quot;path.separator&amp;quot;);&lt;br /&gt;
    final StringTokenizer tokenizer = new StringTokenizer(classpath, pathSeparator);&lt;br /&gt;
    while (tokenizer.hasMoreTokens()) {&lt;br /&gt;
      final String pathElement = tokenizer.nextToken();&lt;br /&gt;
      final File directoryOrJar = new File(pathElement);&lt;br /&gt;
      final File absoluteDirectoryOrJar = directoryOrJar.getAbsoluteFile();&lt;br /&gt;
      if (absoluteDirectoryOrJar.isFile()) {&lt;br /&gt;
        final File target = new File(absoluteDirectoryOrJar.getParent(), name);&lt;br /&gt;
        if (target.exists()) {&lt;br /&gt;
          return target;&lt;br /&gt;
        }&lt;br /&gt;
      } else {&lt;br /&gt;
        final File target = new File(directoryOrJar, name);&lt;br /&gt;
        if (target.exists()) {&lt;br /&gt;
          return target;&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    return null;&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>