aspose file tools*
The moose likes Java in General and the fly likes Can I load classes from a specific jar file at runtime? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Can I load classes from a specific jar file at runtime?" Watch "Can I load classes from a specific jar file at runtime?" New topic
Author

Can I load classes from a specific jar file at runtime?

Henry Leung
Greenhorn

Joined: Oct 26, 2003
Posts: 24
I have a web-app running on an app-server. The app-server has by default loaded an XML parser, but that's too old for my app. I want to use my own version of xerces.jar but I don't want to modify any server setting. So I wonder if it is possible to specify a file path for the targeted xerces.jar at runtime, let my web-app use that jar file's classes, and overrides the loaded ones by the app-server? Any such tricks can be done in the ClassLoader?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Check out java.net.URLClassLoader
You can specify your own ClassLoader then use findResource on that loader to load the files it knows about.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

OK, it seems I misunderstood your question.
Your app has its own version of xerces.jar, but you would like to override this at runtime with your own version of xerces.jar
When you say 'the app server has its own version', you should be able to put your xerces.jsr in the web-inf/lib directory and have it loaded in preference to the one in the application server.
(If you are refering to the deprecated files you may be a able to find a compatibility jar to bridge the gap)
I'm not sure where these jar files are configured, but I hope this helps.
Dave
Henry Leung
Greenhorn

Joined: Oct 26, 2003
Posts: 24
Originally posted by David O'Meara:
OK, it seems I misunderstood your question.
Your app has its own version of xerces.jar, but you would like to override this at runtime with your own version of xerces.jar
When you say 'the app server has its own version', you should be able to put your xerces.jsr in the web-inf/lib directory and have it loaded in preference to the one in the application server.
(If you are refering to the deprecated files you may be a able to find a compatibility jar to bridge the gap)
I'm not sure where these jar files are configured, but I hope this helps.
Dave

The appserver I am using is JRun 3.0, and I found that the one in the application server is loaded in preference to the one in web-inf/lib....
 
Consider Paul's rocket mass heater.
 
subject: Can I load classes from a specific jar file at runtime?