Solved

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

Posted on 2002-07-09
8
852 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 58
hibernate example issues from command prompt 10 50
jsp insert to database example 2 46
jmss example java 2 23
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

856 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