java.lang.ClassNotFoundException at eclipse launch? [message #1063091] |
Wed, 12 June 2013 09:14 |
Kosala Yapa Messages: 159 Registered: September 2010 |
Senior Member |
|
|
Hi there,
plugin ocl.rules->
I implemented a set of rule classes in a package called ocl.rules.
Rule101 implements ILiveRule, Rule102 implements ILiveRule, ... etc.
Then I created a jar file from the plugin ocl.rules.
plugin ocl->
This has ILiveRule interface, Readingjar class, etc.
Readingjar has getRuleObjects() which load rule classes from jar and create rule instances.
Here is that code:
public class ReadingJar
{
static List<ILiveRule> ruleList = new ArrayList<ILiveRule>();
/**
* @param args
* @throws IOException
* @throws ClassNotFoundException
* @throws IllegalAccessException
* @throws InstantiationException
*/
public static void main(String[] args) throws IOException, ClassNotFoundException,
InstantiationException, IllegalAccessException
{
String jarPath = "C:\\eclipse\\Rules\\live\\liveRules.jar";
for (ILiveRule r : ReadingJar.getRuleObjects(jarPath))
{
System.out.println("[In List]>" + r.getClass().getSimpleName() + "<[In List]");
}
}
public static List<ILiveRule> getRuleObjects(String jarPath)
{
List<ILiveRule> ruleList = new ArrayList<ILiveRule>();
File file = new File(jarPath);
URLClassLoader clazzLoader = null;
try
{
clazzLoader = URLClassLoader.newInstance(new URL[] { file.toURI().toURL() });
}
catch (MalformedURLException e2)
{
e2.printStackTrace();
}
JarFile jarFile = null;
try
{
jarFile = new JarFile(file);
}
catch (IOException e1)
{
e1.printStackTrace();
}
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements())
{
JarEntry element = entries.nextElement();
String temp = element.getName();
if (temp.endsWith(".class") && temp.startsWith("rules/Rule"))
{
try
{
// Thread.currentThread().setContextClassLoader(clazzLoader);
String btemp = temp.replaceAll(".class", "").replaceAll("/", ".");
Class<?> c = clazzLoader.loadClass(btemp);
System.out.println((c.newInstance())); // new instance from
// the loaded class
// System.out.println((c.newInstance()).getClass().getSimpleName());
ruleList.add(ILiveRule.class.cast(c.newInstance()));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
return ruleList;
}
}
This main() , is working fine. which loads rule classes and create instances.
Problem:
plugin ocl is added to eclipse run configuration. When I launch run configuration, an exception is thrown.
java.lang.ClassNotFoundException: ocl.live.ILiveRule
Run configuration cannot find ILiveRule interface which is used to implement rules in ocl.rules plugin.
Any help is appreciated.
Thanks in advance.
[Updated on: Wed, 12 June 2013 09:16] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03148 seconds