Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using ClassLoaders to load multiple classes  RSS feed

Femi Alla
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I succesfully used the URLClassLoader to load a class unto the current program I was running but couldn't get to load multiple classes. The directory structure of the classes I'm trying to load is as follows: TheMultitreadedExperiment is a folder that contains "". It calls up 2 other threads in it's subfolders "ThreadTester1", and "ThreadTester2" which contains classes that are named accordingly. I placed the program ( was unsing to load the other classes in the the directory immediately above the the MultithreadedExperiment in the directory hirerchy i.e the direcory in which ClassLoaderTest resides is just outside/contains TheMultiThreadedExperiment folder. I now went ahead to load the class MainThread unto ClassLoaderTest and it worked, but while the program was executing, when it got to the point where it's supposed to call up the others,[The program works normally with the invocation of the MainThread class on the command line, through the use of package statements] the program just terminates. This then lead me to try to load the other programs in the subdirectories unto but couldn't figure out how to do this. I looked up the docs and I found a method in the URLClassLoader class that I think should do the work but can't figure out how to use it. It's findClass(). This is how the docs describe findClass
protected ClassfindClass(String name)
throws ClassNotFoundException
Finds and loads the class with the specified name from the URL search path. Any URLs referring to JAR files are loaded and opened as needed until the class is found.
findClass in class ClassLoader
name - the name of the class
the resulting class
Can anyone please take it up from here? I need help here and any suggestion would be appreciated.

This is the code that worked....till it had to call up the other classes outside/imported in "".

This is my attempt to load the other classes:

Resulting error messages:
C:\JavaPrograms\PersonalPractice\PersonalExperiments>java ClassLoaderTest
An Exception was caught while trying to load your class(es).
lformedURLException: unknown protocol: file:C:\JavaPrograms\PersonalPractice\Per
PS: Please tell me if I put up this question in an inappropriate forum ..i.e this question was supposed to be posted in the advanced section.

Thanks again.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!