0
votes

I want to include a jar file which is used by only 1 package in my project.

|____package1
|____package2
|------------class1
|------------class2
|------------newjar

This is since I am trying to run Unit tests that needs a specific classes contained in this jar.
I do not want this jar for other packages, since I have edited this jar and created another jar for the rest of my project.
Not sure if this is allowed. Found a few articles that speak about including the jar in runtime but that is not what I want, alteast thats what I feel.

2
It seems like what you're asking for is a dynamic classloading environment, such as OSGi. That's quite a heavy-handed approach to a simple and solved problem, assuming your problem is "load a different set of classes when testing than in production". Can you please explain what your end goal is, rather than us help you build on faulty assumptions? - Mark Peters
the text of the question pretty much says I want to be able to use a jar for only one package in my project. The blockquote might be misleading but didnt know how else to explain. - change

2 Answers

0
votes

If you have the ability to edit the jar already, just rename one and include them both. There is no way (that I know of) to add a jar to the build path of only a single package.

0
votes

If you are creating the jar from your own project then while creating the jar use the package/classes you want to be available in the jar. If you are not creating the jar from your own project, let say you are using ODBC jar. In java build path, we include the complete jar which will be vailable in the classpath. So that we can import the resources when required. Hope this answer your questions.