Solved

Temporary Override changes

Posted on 2006-12-01
10
168 Views
Last Modified: 2010-03-31
Is there a way to setup a directory in the classpath, so that any jar files in that directory are looked at.  Or do we have to list each jar file individually.  

If I coluld setup a directory I would add d:\logs\abc\templib to the beginning of the classpath for all app/db/hst servers.  If I have to do it individually I would like to add d:\logs\abc\templib\ArcTemp.jar at the beginning of the classpath.  

What I would like to be able to do is if there's a problem in a program like our Analyzer, we could export the fix to ArcTemp.jar instead of ArcAnalyzer.jar and put that file in the \logs\aul\templib.  This would allow the new code to work until we go through the process of creating tickets and getting it deployed to our production libarary.
0
Comment
Question by:TheVeee
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 300 total points
ID: 18053530
> Or do we have to list each jar file individually

I am afraid you will have to list each jar file individually, except if you write your own classloader which looks automatically in all jar files that can be found inside folders that are in the classpath.
0
 
LVL 24

Assisted Solution

by:sciuriware
sciuriware earned 50 total points
ID: 18054029
You could also leave your CLASSPATH unchanged and put the .jar's in the 'lib\ext' of the JAVA distribution:

on my PC that would be : C:\Program Files\Java\jre1.5.0_09\lib\ext\

;JOOP!
0
 
LVL 12

Assisted Solution

by:enachemc
enachemc earned 150 total points
ID: 18054318
Are you trying to load classes at runtime that are not in the initial classpath of your application? If that is so, you should use custom class loaders.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 24

Expert Comment

by:sciuriware
ID: 18054338
The 'lib\ext' of the JAVA distribution is 'always' in the classpath of the application.

;JOOP!
0
 
LVL 5

Author Comment

by:TheVeee
ID: 18054359
Well kind of...

Basically we want a temp overide library... so for example we have a class say like "CheckThis.java" and we first migrate it to production.  

Now it running and we have a problem within it..

We now want a way to move a temporary fix to a temp library and when the application is running notice its has a new copy in the temp directory with the fix and begin using this until we go through the procedures of moving it to a production.  

So basically its a emergency fix solution....
0
 
LVL 12

Expert Comment

by:enachemc
ID: 18054453
you cannot realy do that. If a class has been loaded, it will not be reloaded by the same class loader. In order to changed the implementation of a class at runtime, you must use custom class loaders. If your class is loaded by the app class loader, you're stuck with it.

You will have to be very very carefuly if you delve into this. If you have two definitions for a class, you will not be able to use one in place of the other. They will not be seen by the compiler as being the same class, though they have the same class name. Classes are compared by java by their refference (==), not by using the equals function.
0
 
LVL 5

Author Comment

by:TheVeee
ID: 18054757
So is there a way to say instead we stop the the application and then it sees the class in the temp class file and uses that one instead of the existing one?

So this would be more like a override area, so when the classloader starts it first checks library a, and if it there it compiles that code, and bypasses not compling the current production class.... so in theory their would only be one class created...
0
 
LVL 12

Expert Comment

by:enachemc
ID: 18059639
yes, there is a way. But it is dangerous (to be read: it should be handled with much care). If you do things right, you will have no problems. The main thing that increases complexity is the number of entry points in the jar(s). If there would be only one entry point (one class that knows itself about the others in the same jar), things would be quite easy.

So, instead of loading the classes from the app class loader, load them in a custom class loader, and use them. When you want to change classes, load the new classes and loose ANY reference to the old classes. If you keep references to the old classes together with the new ones, you could find yourself in quick sands.
0
 
LVL 35

Expert Comment

by:girionis
ID: 18060026
> So is there a way to say instead we stop the the application and then it sees the class in the temp class file and uses that one instead of the existing one?

You will have to write your own classloader that will first be checking the temp folder. If the class is there then it will be loaded otherwise the application classloader will load it from the usual location.
0
 
LVL 35

Expert Comment

by:girionis
ID: 18068453
:)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap bin 2 41
couple of eclipse 5 46
java jdbc batch example 8 41
How to convert String matching to regex in java 4 50
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

838 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