[ajug-members] multiple jar versionsfor one application

Eugene Thompson vttoonses at gmail.com
Thu May 1 11:38:39 EDT 2008


You are close. If you want different versions of the same class, you
either need to change the name of one of them (making it a different
class) or place them in different packages (also making it a different
class).

It seems to me that you want two versions of your WorkerBee class that
have the same interface (contract), but different functionality. Some
standard ways of achieving this are:

// By Inheritance
public class WorkerBee {
   public void doIt() {
      System.out.println("Doing it the old way");
   }

   public void foo() {
     System.out.println("foo execution");
   }
}

public class ImprovedWorkerBee extends WorkerBee {
   public void doIt() {
     System.out.println("Doing it the new, wacky way");
   }
}

public static void main (String[] args) {
   WorkerBee father = new WorkerBee();
   ImprovedWorkerBee son = new ImprovedWorkerBee();

   father.doIt();
   father.foo();
   son.doIt();
   son.foo();
}

Output is something like:
Doing it the old way
foo execution
Doing it the new, wacky way
foo execution


// With Interfaces
public interface WorkerBee {
   public void doIt();
}


public class WBVer1 implements WorkerBee {
   public void doIt() {
     System.out.println("Doing it the old way");
   }
}


public class WBVer2 implements WorkerBee {
   public void doIt() {
      System.out.println("Doing it the new, wacky way");
   }
}



public static void main (String[] args) {
   WorkerBee father = new WBVer1();
   WorkerBee son = new WBVer2();

   father.doIt();
   son.doIt();
}

Output is something like:
Doing it the old way
Doing it the new, wacky way


Note that each class (and interface) would need to be in its own file
(but they could all be in the same package and jar file).

Hope this helps,
Gene

On Thu, May 1, 2008 at 10:54 AM, 521 <521 at ofig.org> wrote:
> i am a java beginner, but from what i've read- it's looked at by name, i
>  would think it would have to be
>
>  org.chrisabney.functors.WorkerBee-v1
>  vs.
>  org.chrisabney.functors.WorkerBee-v2
>
>  -or the like/whatever_name(s)...?  not sure...
>
>  barclay
>
>  On Thu, 1 May 2008 10:25:21 -0400, Chris Abney wrote
>
>
> > Does any one know of a good way to access multiple versions of the same
>  > Jar file from one application.
>  >
>  > For example:
>  >
>  > public class myClass {
>  > :
>  >   public void doIt() {
>  >      org.chrisabney.functors.WorkerBee daddyBee = new
>  > org.chrisabney.functors.WorkerBee();  //The older version
>  >      org.chrisabney.functors.WorkerBee sonBee   = new
>  > org.chrisabney.functors.WorkerBee();  //The newer version
>  >
>  >      daddyBee.doIt(); //The old boring way
>  >      sonBee.doIt();   //The new wacky way
>  >   }
>  > }
>  >
>  > Chris Abney
>  >
>  > _______________________________________________
>  > ajug-members mailing list
>  > ajug-members at ajug.org
>  > http://www.ajug.org/mailman/listinfo/ajug-members
>
>
>  _______________________________________________
>  ajug-members mailing list
>  ajug-members at ajug.org
>  http://www.ajug.org/mailman/listinfo/ajug-members
>



More information about the ajug-members mailing list