Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > adding jars to classpath on runtime without -cp option

Reply
Thread Tools

adding jars to classpath on runtime without -cp option

 
 
rony
Guest
Posts: n/a
 
      11-28-2004
Hi all,

I need to add jar to the classpath on runtime.
When I say runtime I mean without using -cp option when running the program, but
dynamically after the program already started.

I tried to use System.setProperites("java.class.path",newClassPat h) but
It seems there is no effect ( classes are not found ).


any ideas?

Thanks a lot.
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      11-28-2004
On 28 Nov 2004 06:59:03 -0800, rony wrote:

> I need to add jar ..


What jar(s)?

>..to the classpath on runtime.


Why?

> ..any ideas?


Custom classloader.
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ClassLoader.html>

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
 
 
 
Ferenc Hechler
Guest
Posts: n/a
 
      11-28-2004
You can use URLClassLoader to do the class-loading.
Take a look at the following thread:
http://forum.java.sun.com/thread.jsp...rt=15&tstart=0

bye, feri


 
Reply With Quote
 
rony
Guest
Posts: n/a
 
      11-29-2004
Andrew Thompson <(E-Mail Removed)> wrote in message news:<geiqvmfi1crk.ug6mnkleaqmh$(E-Mail Removed)>.. .
> On 28 Nov 2004 06:59:03 -0800, rony wrote:
>
> > I need to add jar ..

>
> What jar(s)?
>
> >..to the classpath on runtime.

>
> Why?
>
> > ..any ideas?

>
> Custom classloader.
> <http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ClassLoader.html>


1. about the why and the jars. I'm writting testing environment, the
testing environment supply easy api for logging,telnet.... and api for
other professional tools. the user write the tests in java and I have
no control on his the code, the user may use log4j for example which
means I need to add it to my classpath. so you ask your self why I
dont just add it to the batch file ?
well, there is code that is version dependent, when I run regression I
want to use os2.5 and app2.2 which means different jars then the
current set I work with which is os2.6 ... and I want to read those
jars from ini file so I can make Ini file for each setup ( I know I
can do bacth for each setup ).
That why I want to add jars to my class path after the program already
up( I hope this is not to complicated ).

2. I want the VM machine to find those classes the user use. I know
how to load class that I know it's name in advance.

any ideas?
 
Reply With Quote
 
rony
Guest
Posts: n/a
 
      11-29-2004
"Ferenc Hechler" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> You can use URLClassLoader to do the class-loading.
> Take a look at the following thread:
> http://forum.java.sun.com/thread.jsp...rt=15&tstart=0
>
> bye, feri


Hi,

The problem is that I don't know the name of the class that is going
to be used. I just know that jar where it is located. I want the VM to
look there.

Thanks,
Rony
 
Reply With Quote
 
rony
Guest
Posts: n/a
 
      11-29-2004
"Ferenc Hechler" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> You can use URLClassLoader to do the class-loading.
> Take a look at the following thread:
> http://forum.java.sun.com/thread.jsp...rt=15&tstart=0
>
> bye, feri


Hi,

The problem is that I don't know the name of the class that is going
to be used. I just know that jar where it is located. I want the VM to
look there.

Thanks,
Rony
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      11-29-2004
On 28 Nov 2004 23:28:22 -0800, rony wrote:

> I want the VM machine to find those classes the user use. I know
> how to load class that I know it's name in advance.


Do a File.list() on the directory. Present the user with a JList
of jars if more than one is found. Get the enumeration of the
ZipEntries from the selected Jar and them's your classes.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
Ferenc Hechler
Guest
Posts: n/a
 
      11-29-2004
Hi Rony,

thats exactly what the Class "ClassPathHacker" is doing,
Perhaps you should look at the thread
http://forum.java.sun.com/thread.jsp...art=0&tstart=0
again.
There are two solutions mentioned.
One using reflections to access the protected method addURL of ClassLoader
and the other changing the Thread-Context ClassLoader using
Thread.currentThread().setContextClassLoader .

bye,

feri


"rony" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) om...
> "Ferenc Hechler" <(E-Mail Removed)> wrote in message
> news:<(E-Mail Removed)>...
>> You can use URLClassLoader to do the class-loading.
>> Take a look at the following thread:
>> http://forum.java.sun.com/thread.jsp...rt=15&tstart=0
>>
>> bye, feri

>
> Hi,
>
> The problem is that I don't know the name of the class that is going
> to be used. I just know that jar where it is located. I want the VM to
> look there.
>
> Thanks,
> Rony



 
Reply With Quote
 
rony
Guest
Posts: n/a
 
      11-30-2004
"Ferenc Hechler" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Hi Rony,
>
> thats exactly what the Class "ClassPathHacker" is doing,
> Perhaps you should look at the thread
> http://forum.java.sun.com/thread.jsp...art=0&tstart=0
> again.
> There are two solutions mentioned.
> One using reflections to access the protected method addURL of ClassLoader
> and the other changing the Thread-Context ClassLoader using
> Thread.currentThread().setContextClassLoader .
>
> bye,
>
> feri
>
>
> "rony" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:(E-Mail Removed) om...
> > "Ferenc Hechler" <(E-Mail Removed)> wrote in message
> > news:<(E-Mail Removed)>...
> >> You can use URLClassLoader to do the class-loading.
> >> Take a look at the following thread:
> >> http://forum.java.sun.com/thread.jsp...rt=15&tstart=0
> >>
> >> bye, feri

> >
> > Hi,
> >
> > The problem is that I don't know the name of the class that is going
> > to be used. I just know that jar where it is located. I want the VM to
> > look there.
> >
> > Thanks,
> > Rony


Hi,

an answer at last.

thanks a lot feri.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add *.jars to *.jars possible/recommendend? Eclipse setup for this? Ulf Meinhardt Java 2 02-03-2010 04:11 PM
How to automatically include all *.jars in a dir tree WITHOUT explicit CLASSPATH assignment ? Lars Willich Java 9 08-28-2007 01:07 AM
Loading image from jars from other jars etc JavaEnquirer Java 2 02-22-2006 03:42 PM
JARs containing JARs alan@engrm.com Java 5 05-19-2005 04:55 PM
exec jars w/dependent jars Ike Java 6 09-24-2004 06:03 PM



Advertisments