• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime selection of Jar to use?  RSS feed

 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've a J2EE web application that generates reports. My reports generation depends on a third party Jar file. Currently there're 2 versions of the Jar that we're using. Half of our reports use the older version, while the other half use the newer version.

We're hoping that we could avoid a full upgrade of all our reports as this would be too time-consuming.

We'd included the older version Jar in the classpath. We're using WebLogic 7 server.

Is it possible for us to use both versions of the Jar? As in could we dynamically decide at runtime to select which Jar to use for the report generation?

Any suggestions are welcomed & help is greatly appreciated

Thanks!
 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a example for you. Hope this would help you out. Watchout both method, what you have to do, is just change the jar file path.

This shim class will do nothing but call the methods of an instance of a JDBC driver that we loaded dynamically.



 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anand,

Let me see if I understood you correctly. By specifying the specific Jar entry URL for the Jar versions, I can then load the correct version of the class to use in my codes.

And I've to remove the Jar from my classpath.

Thanks!
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I kept encountering the NoClassDefFound error with my codes. It seems that I'd managed to load the class from the Jar, but when I tried to instantiate an object & then type-casting it to the specific class, the NoClassDefFound error would strike me without fail.

Here's my codes:


Could anyone see what am I missing or doing wrongly?

Also, as you could see, I need to do a type-casting, so I would need to import this class & during compilation, the Jar has to be in my classpath. So am I in a paradox? I don't want the Jar to be in the classpath, but its needed for compilation.

Any help is much appreciated. Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!