So I dynamically load a jar at runtime how do I use it?

Posted by justinhj on Stack Overflow See other posts from Stack Overflow or by justinhj
Published on 2010-04-26T16:04:17Z Indexed on 2010/04/26 16:13 UTC
Read the original article Hit count: 168

Filed under:
|

So question 194698 shows how to load a jar file at runtime and you can load individual named classes and get a Class object. Now my problem is I want to be able to cast those Classes to the types they really are, but I can't because I can't use an import since the whole point is to load it at runtime rather than compile time.

It seems like the way to go is to use reflection to discover the functions and field names, but that seems brittle since the API in the jar files could change and the code won't break until it is run.

Is there a better way?

© Stack Overflow or respective owner

Related posts about java

Related posts about jar