Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » java.lang.ClassNotFoundException at eclipse launch?
java.lang.ClassNotFoundException at eclipse launch? [message #1063091] Wed, 12 June 2013 09:14 Go to next message
Kosala Yapa is currently offline Kosala YapaFriend
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

Re: java.lang.ClassNotFoundException at eclipse launch? [message #1063105 is a reply to message #1063091] Wed, 12 June 2013 10:45 Go to previous message
Kosala Yapa is currently offline Kosala YapaFriend
Messages: 159
Registered: September 2010
Senior Member

I did solve the issue.

improved the following statement.

clazzLoader = URLClassLoader.newInstance(new URL[] { file.toURI().toURL() },
ReadingJar.class.getClassLoader());


Cheers,
Previous Topic:Modify TypeDeclaration (class) with AST
Next Topic:Own Launch implementation doesn't see classes from other bundles
Goto Forum:
  


Current Time: Thu Apr 25 08:54:02 GMT 2024

Powered by FUDForum. Page generated in 0.02882 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top