1

I've got a question on how to add a jar file with code.

The situation is that I want to allow the customers to choose themselves, which database should be connected. Therefore, I'd like to give them the opportunity to load a custoom *.jar into the running software (similar to Add external library in eclipse).

Is there a way how I can manage that? I was trying kind of

import System.getProperty("java.io.tmpdir") + "\\dbdriver.jar";

java.io.tmpdir\dbdriver.jar would be the file, where custom jar-library-imports will be stored by my code. But eclipse didn't seem to like it.

Do you have any idea?

Maroun
  • 94,125
  • 30
  • 188
  • 241
Axylo
  • 13
  • 2
  • Have you considered using a framework like [OSGi](http://en.wikipedia.org/wiki/OSGi) for this? – Björn Pollex Nov 26 '12 at 10:45
  • 3
    you can use OSGi, or look at this answer: http://stackoverflow.com/questions/3811545/on-the-fly-class-loading-with-jars – Ahiel Nov 26 '12 at 10:46
  • Duplicate of http://stackoverflow.com/questions/60764/how-should-i-load-jars-dynamically-at-runtime and http://stackoverflow.com/questions/194698/how-to-load-a-jar-file-at-runtime – Udo Klimaschewski Nov 26 '12 at 10:46

3 Answers3

0

This is a problem of loading jars at runtime. Please take a look at the following link which is pretty similar to what you're looking for.

Loading jars at runtime

Community
  • 1
  • 1
ayan_2587
  • 833
  • 2
  • 11
  • 21
0

If this is what you are trying to accomplish in a .java file it is not correct, you cannot reference a jar file directly in a java file, you can just import single classes or a group of classes using wildcard '*'.

The best approach, to my knowledge, here would be to install an ORM library and then decide with the client what his choice for "more than one" RDBMS would be.

OverLex
  • 2,501
  • 1
  • 24
  • 27
0

You'll need to read up on Classloaders and Reflection in order to get an understanding of how this works.

carlspring
  • 31,231
  • 29
  • 115
  • 197