Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Same class but different package and different jars

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class "ISO8601DateFormat" which is present in 2 different jars of (1)."jackson-mapper-asl-1.9.12.jar" and (2)."log4j-1.2.15.jar". It compiles fine since i have added both the jars in the build path of eclipse.But during runtime it couldn't recognize exact class from the (1) jar instead same class is loaded with different package name from (2) jar.

Please gimme a way of loading this class from (1) jar and ignoring the same from (2) jar.Please let me know if you have idea of doing this in manifest file instead of dynamic class loading since i dont want to touch my code.

Thanks in advance and expecting right solution soon folks!
 
Marshal
Posts: 70370
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
“Same class” entails “same package”. If the classes are in different packages, they are different classes. If they have the same simple names, you may have to use their fully‑qualified names throughout.

If you really have two classes with the same fully‑qualified name in the two .jars, I do not think there is a solution, since the class loaders do not specify any order that they load such classes in so as to resolve the ambiguity. When you do the coding in Eclipse, beware of the dropdown lists from ctrl‑space. Those classes may not appear in the order you expect.
 
raghav prakasam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is the Class:




And during an ANT build, showing the below error:

[javac] C:\workspace\XXX\xxx\xxx\xxx\xxx\xxx\xxx\xxx\CustomDateMapper.java:13: cannot find symbol
[javac] symbol : class ISO8601DateFormat
[javac] location: package org.codehaus.jackson.map.util
[javac] setDateFormat(new org.codehaus.jackson.map.util.ISO8601DateFormat());

[javac] C:\workspace\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\CustomDateMapper.java:6: cannot find symbol
[javac] symbol : class ISO8601DateFormat
[javac] location: package org.codehaus.jackson.map.util
[javac] import org.codehaus.jackson.map.util.ISO8601DateFormat;


It is showing both places including import.Instead if i modify my code pointing log4j's class as shown below, build is happening:

setDateFormat(new org.apache.log4j.helpers.ISO8601DateFormat());
 
Campbell Ritchie
Marshal
Posts: 70370
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to know which .jar the classes are in and which package before you import them.
This discussion is gradually becoming confusing. Please unzip the .jars and search them and find how many ISO8601… classes there are, and which packages they are in.
 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic