import java.io.*; import java.lang.reflect.Method; import java.util.*; import java.net.*; class A { @SuppressWarnings("deprecation") private static final Class[] parameters = new Class[]{URL.class}; public static void addFile(String s) throws IOException { File f = new File(s); addFile(f); }//end method public static void addFile(File f) throws IOException { addURL(f.toURL()); } public static void addURL(URL u) throws IOException { URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class sysclass = URLClassLoader.class; try { Method method = sysclass.getDeclaredMethod("addURL",parameters); method.setAccessible(true); method.invoke(sysLoader, new Object[]{u}); } catch (Throwable t) { t.printStackTrace(); throw new IOException("Error, could not add URL to system classloader"); } } public static void main(String[] args) throws IOException { String u="E:\\javadem\\"; addFile(u); Class.forName("B"); System.out.println(System.getProperty("java.class.path")); B obj=new B(); //here, it shows the error. } }
B cannot be resolved to a type
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)