Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

import confusion!!

for example.. I have two .jar files in my ext. jdom.jar and eva3rt.jar
when i do import org.jdom.*, which one will be imported, because both jar contents org.jdom.

similar confusion when i use implements provided by third party. for example jtapi.jar gives APIs and Xtapi.jar gives its implementation. but in our application we use the APIs. So how this mapping takes place...
 .. infact I'm even confused with my this query.. so anyone can provide me a link from where I can understand these stuffs.

Thanks in Advance..

0
RupeshB
Asked:
RupeshB
  • 2
  • 2
  • 2
  • +5
2 Solutions
 
Ajay-SinghCommented:
The discovery of classes is done sequencely as the jar appears in the classpath.
0
 
RupeshBAuthor Commented:
then how to change orders of jars
0
 
hoomanvCommented:
like this

set CLASSPATH=jdom.jar;eva3rt.jar;.
or
set CLASSPATH=eva3rt.jar;jdom.jar;.

whichever comes first, has priority over the other
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
RupeshBAuthor Commented:
that's ok but not effective way... still waiting for full answer...
0
 
girionisCommented:
If you put them in the /ext folder I think it will be done alphabetically. If you want different order you will have to take them out of /ext and put them in your user-defined classpath.
0
 
colr__Commented:
To avoid any amibiguity you should use the fully qualified name of your class in the import. This makes your code easier to read, maintain, and removes any ambiguity.

colr__
0
 
mukundha_expertCommented:
right, but the question is about same package in diferent jars
0
 
mukundha_expertCommented:
If you are using eclipse you can specify the jars for each project,

do you need both these jars in the same project??

if two jars have same package and are in the same project then the behaviour  might not be as you expected.

so wat you can do is seperate your aplication into two projects. in one project add the first jar
and in the second one the second jar. split your apllication based on that. later you can combine both of them using a third project or may be in anyone of the projects
0
 
bpmurrayCommented:
> that's ok but not effective way... still waiting for full answer...

I think you're looking for a little magic - it doesn't exist. The reality is that if you have conflicts in your jars, that's your problem, and you should probably fix that before you worry about the order in which they're loaded (which is, as explained above, the order in which they're "seen" by the JVM).
0
 
colr__Commented:
mukundha_expert  > your right, I was assuming that the package names just happened to be the same (in which case the class names would be differnet maybe), not that they were actually the same package.
0
 
WebstormCommented:
If you want to use both classes, you can try to use 2 different class loaders, and use the one containing the package you want to use.


>> similar confusion when i use implements provided by third party. for example jtapi.jar gives APIs and Xtapi.jar gives its implementation. but in our application we use the APIs. So how this mapping takes place...

The API may have something to know which classes implement it. It may be a configuration file containing fully-qualified class names, or you have to explicitly give this class name when you call the API.
Or you have to direclty use the implementation classes.
0
 
bpmurrayCommented:
Typically the APIs contain abstract base classes and the implementation jar contains the concrete implementations of these. It depends on whether you're calling the functionality (use the implementation jar) or implementing it yourself (use the API jar).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now