Solved

How to override/overload method "findLibrary()" inside ClassLoader ??

Posted on 2002-07-09
8
827 Views
Last Modified: 2013-12-29
I create my own ClassLoader and use it load another application---one java class with main method.  Another application has a lot of help files. In order to run this new application, I have to set up classpath dynamically for these help classes. As I know, I should override/overload method findLibrary(), it can set up classpath dynamically, and when I load class with main, it will find my help classes as library(e.g. my library:help.jar and help2.jar), so I can really run a new application from my old application.  But how to overload or override method findLibrary() ?? I have no idea ?? Thanks for help.
Gary
0
Comment
Question by:garyshi
8 Comments
 
LVL 35

Expert Comment

by:girionis
Comment Utility
 You will just define a findLibary() method in your class and you will provide your own implementation. That's overriding.

  By the way overloading is a different concept from overriding. The "+" operator is overloaded since it works for string concatenations and for addition. When you write a Java applet and you provide your own implementation for he paint() method then this is overriding.

  Hope it helps.
0
 

Author Comment

by:garyshi
Comment Utility
Hi qirionis,
Thanks for your reply. I hope some one can give me a sample code or if it is not difficulty, write a few line simple code for me.  

Suppose I have two jar files (help.jar and utility.jar) and I want to add these two jar files to classpath or to library, how to write findLibrary() method so it can add these two jar files into library. When I load a java  class (e.g. Start.java, it has a main method, it need help.jar and utility.jar when it run), I can run the this class and this application. Thanks, Gary
0
 

Author Comment

by:garyshi
Comment Utility
Hi qirionis,
Thanks for your reply. I hope some one can give me a sample code or if it is not difficulty, write a few line simple code for me.  

Suppose I have two jar files (help.jar and utility.jar) and I want to add these two jar files to classpath or to library, how to write findLibrary() method so it can add these two jar files into library. When I load a java  class (e.g. Start.java, it has a main method, it need help.jar and utility.jar when it run), I can run the this class and this application. Thanks, Gary
0
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
Comment Utility
findLibrary() has nothing to do with loading classes, it returns the path to a required native library.

Also to load extra classes at runtime does not necessarily require a custom class loader. Have a look at the URLClassLoader class, or alternately simply extract your jar file into your existing classpath and the standard class loader will find the classes.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 3

Assisted Solution

by:daitt
daitt earned 100 total points
Comment Utility
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
 I am not sure what exactly you are trying to do, but this tutorial in class loaders might come in handy:

  http://www-105.ibm.com/developerworks/education.nsf/java-onlinecourse-bytitle/06B49359139A1AD186256A310049AC9B?OpenDocument

  Hope it helps.
0
 

Author Comment

by:garyshi
Comment Utility
Hi
Thanks all of you. I will check these messages and documents.
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- split points between daitt and objects

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now