load external jar in to class path for java project

2.4k views Asked by At

I have a lib folder at installer location that i want to load at class path or refrenced at runtime for my java project, programmaticaly.

I have tried to set classpath by -cp and used ClassLoader, URLClassLoader but it did't work. found ClassNotFoundException. I also tried static block to load my jar.

How to resolve it, how can we referenced external jar folder dynamically or can load it at class path.

I am using Eclipse IDE which have option in build path to load external folder but i am not sure it will work when i export the project as it is building path for my current workspace only so it would't work when installer go in others machine. So i required to load that folder programatically.

2

There are 2 answers

0
XXX On

you can use environmental variable to load the class or jar.

1
Srikanth Ganji On

Please have a look at these questions in stackoverflow it self. they may help you. I personally haven't tried and never came across this kind of requirement.

How should I load Jars dynamically at runtime?

Loading jars at runtime

Hope above links help you to solve your problem.