adding jars to classpath on runtime without -cp option

R

rony

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",newClassPath) but
It seems there is no effect ( classes are not found ).


any ideas?

Thanks a lot.
 
R

rony

Andrew Thompson said:

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

Andrew Thompson

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

rony

Ferenc Hechler said:
Hi Rony,

thats exactly what the Class "ClassPathHacker" is doing,
Perhaps you should look at the thread
http://forum.java.sun.com/thread.jspa?threadID=300557&start=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

Hi,

an answer at last.

thanks a lot feri.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top