-1

I have a weird situation where a class "User.java" has been defined in two maven projects(A & B), under exact same package structure. My maven project has dependency on both A & B. However 'User.java' in project has an extra field. I want to specify and make sure that I always use the 'User.java' from project A. But unfortunately, it is always picking from Project B.

How do i tell the compiler to import the class from specific/desired project?

Punky
  • 97
  • 1
  • 12
  • 2
    You cannot. You are at the mercy of the classloader(s) – Brett Okken Jun 25 '16 at 16:24
  • 2
    This is a REALLY BAD IDEA. Reconcile the two definitions into one and make it a dependency of the two projects that currently use it. – Jim Garrison Jun 25 '16 at 16:35
  • Yes, i do agree that. But I was thinking if there is way that tells my system, may be maven, that A's User.java overrides B's User.java. – Punky Jun 25 '16 at 16:37
  • @JimGarrison Yes, Its a real bad bad idea. Developers/Architects should have thought about it. Yes, making both A & B has dependency on C, lets say, who has User.java, will resolve. But the situation here is that these two components are owned by two different teams. To do any change might take a good amount of time, if it at all they agree to do. I am looking for a workaround to get me going .:D – Punky Jun 25 '16 at 16:43

1 Answers1

1

I normally don't answer a question with "Don't do this", but I'll make an exception in this case.

This is a REALLY BAD IDEATM.

As has been pointed out, you are at the mercy of the RUNTIME classpath, over which you have little absolute control, especially if a different group of people is responsible for configuring and provisioning your production environment.

The time to address and resolve this issue is YESTERDAY. This should have never been allowed to happen, and continuing with this will just lead to continual headaches and unexplained, hard-to-debug failures in the future.

Get the architect(s) involved and either

  1. Rename both of the User classes, for example AccountingUser & SalesUser. Do not allow one to remain User if there are legitimately two kinds of users; or
  2. Reconcile the two definitions, then pull it out to its own library (along with any common supporting code) and make both projects depend on it.
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190