aspose file tools*
The moose likes JSF and the fly likes Dynamic loading of class from external jar and NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Dynamic loading of class from external jar and NoClassDefFoundError" Watch "Dynamic loading of class from external jar and NoClassDefFoundError" New topic
Author

Dynamic loading of class from external jar and NoClassDefFoundError

daniele licitra
Ranch Hand

Joined: Apr 08, 2013
Posts: 37

Hi to all.
I don't know if this is the correct thread to post in my question.

What is the situation?
I've a web application, we call it WA, that uses JSF. WA run on Glassfish 3.
This application has some panel (extended from primefaces.Panel) and i want to bind the panel to some object P:

The panel must be loaded dynamically from an external jar.

The P class is something like


The ModTest class is in another jar file, called ModTest.jar. I want to load the class at runtime from the external jar so i can change the "panel" without recompile WA.

So, I built a bean B that read from database the path of jar file and the classname.
B then must instantiate an object A of tipe P and return A.pannello to show it on screen.

The loader function is:




What is the problem?
It works untill instance = classToLoad.newInstance(); at this time throw java.lang.NoClassDefFoundError: com/bss/primefaces/panel/BssPanel.
com/bss/primefaces/panel/BssPanel is missing or it is not found. That class is in another library, component.jar.
The ModTest.jar hasn't component.jar inside but WA.war has it.

What are the questions?
- ModTest.jar is a maven project so, how i can force to put all dependency jar in ModTest.jar? It solve the problem? I need to create a normal java project?
otherwise
- There is a way to provide the necessary jar without modifing ModTest.jar, like read it from glassfish's lib directory? How I must provide all the dependencies in the correct way?

Thanks, sorry for my bad English.

JPA 2.1.0
Glassfish 3.1->4, Wildfly, Primefaces 3.4->4
daniele licitra
Ranch Hand

Joined: Apr 08, 2013
Posts: 37

Solved.

In external jar ModTest.jar, in pom.xml, put the maven plugin:


now all dependency are exploded inside the jar. It works.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic loading of class from external jar and NoClassDefFoundError