Solved

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

Posted on 2002-07-09
8
831 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
ID: 7141484
 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
ID: 7141881
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
ID: 7141918
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
ID: 7142028
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Assisted Solution

by:daitt
daitt earned 100 total points
ID: 7142446
0
 
LVL 35

Expert Comment

by:girionis
ID: 7142746
 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
ID: 7144160
Hi
Thanks all of you. I will check these messages and documents.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8916917
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

932 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

10 Experts available now in Live!

Get 1:1 Help Now