?
Solved

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

Posted on 2002-07-09
8
Medium Priority
?
890 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 92

Accepted Solution

by:
objects earned 400 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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

771 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