• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Same Class name & package name for 2 classes

 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in my product, their are two classes in two different PROJECT with the Same Class name & package name. Based on the which class files order, the FIRST was getting loaded.....but another is not getting loaded ..... so i have to restart the server by changing the class path order every time....

Is there any way where we can have two classes can be loaded into the server with any issues???.... i heard some thing like you can keep two different class loaders which will loaded different classes... but not sure how can i do this for a application in weblogic server...

any lights on this thanks in advance ;)

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a recipe for a perfect maintenance nightmare--I'd fix it at the source, rather than trying to work around it.

Barring that, if the "other" same class is in a separate jar I'd probably use a library manipulation tool to change its name.
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are both project loaded in same JVM somehow (though I don't myself that whether this can be done or not? Someone please can help me at this) ? Then you can use classloader to load unload desired classes.
 
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohammed Yousuff wrote:in my product, their are two classes in two different PROJECT with the Same Class name & package name.
Is there any way where we can have two classes can be loaded into the server with any issues???



Change one of the package names, add a subdirectory or something to make it unique.
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pat Farrell wrote:Change one of the package names, add a subdirectory or something to make it unique.



What if he is using jar files or has no direct access to those classes. Changing in existing directory structures, may affect other programs and more changes need to be done then.
 
Pat Farrell
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahul.p Kumar wrote:What if he is using jar files or has no direct access to those classes. Changing in existing directory structures, may affect other programs and more changes need to be done then.



Yes, but I see no other reliable solution. If they are external jar files, shame on the vendor for using duplicate names. If you have source, change one.

Playing games with class loaders will work for a while, or rather may work for a while, but its not a long term reliable solution.
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pat Farrell wrote:If they are external jar files, shame on the vendor for using duplicate names.



Why shame? They are two different projects and may have same name by coincident or incident. The question put here is not very clear, though and I answered based on assumptions that let it be same name, now first question that myself do not know that how come two different project packages are conflicting each other? is it because they are in same jvm memory space ? (Then it becomes my question that whether it can be done ?). Second question is say it is done somehow, now is it ok to change the directory structures of respective projects or other measures should be taken up?
 
Pat Farrell
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahul.p Kumar wrote:Why shame? They are two different projects and may have same name by coincident or incident.



Because the naming convention is to include the name of the company in the package name.
org.apache.log4j.Logger; com.google.common.collect.ImmutableSet; com.sun.mail.dsn ... the list goes on and on.

The Internet domain namespace is unique on the whole Internet, essentially the whole world. This the package name within a company is completely under the control of the company.

There is no limit on the choice of names, or number of levels (perhaps some high limit, but none that matter), you can invent a project name and make it unique.

If you are too lazy to do that, you deserve to be publicly shamed.
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pat Farrell wrote:
If you are too lazy to do that, you deserve to be publicly shamed.


It is not matter of too lazy . Think about same company two projects, two teams and a coincident. Leave the shame word for the people for whom the end of the world is near by. Any type of mistake is possible and at any point of time, no matter how religiously you follow the standards.
 
Pat Farrell
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahul.p Kumar wrote:It is not matter of too lazy . Think about same company two projects, two teams and a coincident.


Sorry, but I disagree with your justification. For a publicly released API, its unprofessional, as it is trivial to pick a unique name. Even huge global corporations do it properly. If your code is designed in one city, use the city in the package name, or your department.

For example, my old company could use com.cybercash.bangalore.set.... or com.cybercash.research....

If Google and Sun can do it, anyone who cares can do it.

 
Master Rancher
Posts: 5120
82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's possible for two groups to independently come up with the same name at approximately the same time, yes. But at some point, those groups must become aware of each other. At that point, it is the moral responsibility of both groups to resolve the situation, and at least one of those groups must change their name. Typically, whoever chose their name first will keep it, and the second group must choose another. To do otherwise would be completely irresponsible.

If you've got a really big company, and somehow the name collision is not detected until one group or the other has moved on to another project... well, that's a sign of a very badly organized company.

A collision like this seems much more possible among open-source projects - jamón and JAMon come to mind. Both apparently started about the same time, and both probably would naturally have chosen "org.jamon" as the base of their package structure. But my guess is, jamón managed to register the domain first, and that was that - JAMon pretty much had to change to a different package name at that point. Because duplicating one already in use would be irresponsible.

Yes, in rare cases, coincidences may happen. But they need to get resolved.
 
Pat Farrell
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:... managed to register the domain first, and that was that...Yes, in rare cases, coincidences may happen. But they need to get resolved.


The beauty of the Sun stylistic choice is that the issue of domain registration is already solved, and solved by someone not associated with Java. We can just use it. This makes it a previously solved problem, and we can just use the solution.
 
Mike Simmons
Master Rancher
Posts: 5120
82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, exactly.

By the way, I'm just speculating on what happened with jamón vs JAMon. But the creator of JAMon, is a regular here, so maybe he'll offer his take. I note that jamon.com was taken by a commercial site, so maybe JAMon chose to keep the .com and change the JAMon part, becoming jamonapi.com, rather than keep the jamon and change the .com. Either way it's too bad, because JAMon makes a pretty cool name, what with the Rastafarian color scheme used at their site.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the same problem as Mohammed. I am using two libraries with the same name and package. Maven can compile them alright. Eclipse+m2eclipse cannot though.
 
Marshal
Posts: 80254
428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are going to have to change the name of one package.
 
Jerome Pacleb
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the interest of time... Maybe later on...
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could load them in separate ClassLoaders, but in my opinion that way lies madness
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic