• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

loading classes from jar file at runtime

 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
follwing scenario:
an app downloads a jar file and creates objects from classes stored in this jar.
how do i load classes from this jar file (the file is not in the classpath -> its not found by the system class loader)
is there a way how i can add a jar file to the classpath dynamicaly ?
or do i have to create a URLClassloader and load all the classes trough reflection ?
thanks
karl
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't dynamically set the classpath at runtime. The classpath system property that is set when starting the VM can be modified at runtime, but the system classloader is already configured with the classpath status at VM start time by then.
You'll have to use a custom classloader to load your classes, or you could use the URLClassLoader you mentioned.
Regards,
G´┐Żnther
http://www.javacoding.net
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.
i did it with the URLClassloader and it works.
k
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic