I have an abc.jar and I'm loading a class using reflection. But I'm getting a ClassNotFoundException. My code is as below:
File file1 = new File(ApplicationContext.getPath()+"lib/abc.jar");
Class noparams[] = {};
URL url = file1.toURI().toURL();
URL[] urls = new URL[]{url};
@SuppressWarnings("resource")
ClassLoader cl = new URLClassLoader(urls);
cls = cl.loadClass("com.abcd.feat.udf.MobileUDF");
Constructor<?> c = cls.getConstructor();
mobileUDFActions = c.newInstance();
I have verified that the jar is present in ApplicationContext.getPath()/lib folder.
Contents of jar are appropriate. It contains classes in the package com/abcd/feat/udf.
Please help me realize what is the mistake. I'm getting below exception.
java.lang.ClassNotFoundException: com.abcd.feat.udf.MobileUDF
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.abcd.feat.core.TestScriptExecutor.<init>(TestScriptExecutor.java:85)
Aucun commentaire:
Enregistrer un commentaire