Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Instantiating classes in jar file used by Web project

Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I'm developing an application using Websphere 5.
Currently having an issue with class instantiation and hope someone could enlighten my day.
The situation is that I have a Web project called TestWeb that references a utility jar file called utility.jar
Within that utility.jar file I have a class that uses dynamic class loading to create a class existing inside TestWeb. The code is
Class adapterclass = Class.forName(cName);
where cName is a class existing in TestWeb.

When the above line exceutes I get a NoClassDefFoundException. As far as I know the class definition should have been loaded as the class file sits inside the WEB-INF\classes directory of TestWeb. If thats the case then any other jar files being used by the TestWeb application should have access to this classpath.

Am I right or am I extremely convoluted in my thinking?
Any help would be greatly appreciated.

Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may want to check the following on your server properties in the admin console.

Application Classloading Mode
Specifies whether the class loader should search in the parent class loader or in the application class loader first to load a class. The standard for JDK class loaders and WebSphere class loaders is PARENT_FIRST. By specifying PARENT_LAST, your application can override classes contained in the parent class loader, but this action can potentially result in ClassCastException or LinkageErrors if you have mixed use of overriden classes and non-overriden classes

Just verify this option in your admin console for the server configuration.

Just wondering...are you giving the fully qualified name of the class when you are loading the class i.e. with Package name.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic