Solved

import confusion!!

Posted on 2006-06-28
12
389 Views
Last Modified: 2012-06-21
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
Comment
Question by:RupeshB
  • 2
  • 2
  • 2
  • +5
12 Comments
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 100 total points
ID: 17007113
The discovery of classes is done sequencely as the jar appears in the classpath.
0
 

Author Comment

by:RupeshB
ID: 17007120
then how to change orders of jars
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17007215
like this

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

whichever comes first, has priority over the other
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

Author Comment

by:RupeshB
ID: 17007298
that's ok but not effective way... still waiting for full answer...
0
 
LVL 35

Expert Comment

by:girionis
ID: 17007356
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
 
LVL 8

Expert Comment

by:colr__
ID: 17007567
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
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17007765
right, but the question is about same package in diferent jars
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17007787
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
 
LVL 15

Expert Comment

by:bpmurray
ID: 17007843
> 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
 
LVL 8

Expert Comment

by:colr__
ID: 17007847
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
 
LVL 13

Accepted Solution

by:
Webstorm earned 150 total points
ID: 17008348
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
 
LVL 15

Expert Comment

by:bpmurray
ID: 17009121
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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 119
more than one jdk and one jre 1 50
spring jars download 1 35
web project error add remove 1 29
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question