Solved

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

Posted on 2002-07-09
8
842 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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
 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to parse custom JSON to POJO java 4 74
reverse digits of a number using for loop 5 45
tomcat not starting 6 45
SHA2 certs for IIS AND Java? 2 94
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

822 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