Reloading the same jar at runtime

Hi Friends,
I have loaded the jar at runtime using the urlclassloader, but now I want to reload the same jar of different version again.
Is it possible, if yes ..Could you please explain.
Thanks in advance,
Kk

If your application permits, you can do this:
1. Create an URLClassLoader with an URL referencing the original version of the JAR;
2. Create an instance of a class, most probably a Runnable, keeping a reference to it;
3. Use the object created in 2.
And when you want to reload the JAR, you set the reference to null, perform any cleanup needed, and repeat those three steps again.
Something like
public class MyApplication {
  public static void main(String[] args) throws Exception /* error handling removed for clarity */ {
    URLClassLoader loader = new URLClassLoader(new URL[] {new URL("name.jar"});
    Runnable run = (Runnable) loader.loadClass("com.mypackage.MyApplicationStage2").getConstructor().newInstance();
    run.run();
    System.out.print("Press Enter to reload name.jar, or Ctrl+C to exit: ");
    new BufferedReader(new InputStreamReader(System.in)).readLine();
    run = null;
    loader = new URLClassLoader(new URL[] {new URL("name.jar"});
    Runnable run = (Runnable) loader.loadClass("com.mypackage.MyApplicationStage2").getConstructor().newInstance();
    run.run();
}And then the class in name.jar could look like this (old, then new):
package com.mypackage;
public class MyApplicationStage2 implements Runnable {
  public void run() { System.out.println("Old code"); }
package com.mypackage;
public class MyApplicationStage2 implements Runnable {
  public void run() { System.out.println("New code"); }
}Edited by Looce on Nov 8, 2008 6:00 PM (three steps, not two)

Similar Messages

  • Multiple download of the same JAR file

    We have a collection of applets packaged in a single JAR file. Some users (web developers that use our applets) have been complaining that the applet is extremely slow to start up.
    When the html page includes more than one applet from the same JAR file then, "ONLY IN SOME CASES", the JAR file is downloaded multiple times.
    By capturing network traffic we can also think that the JAR file is downloaded even when accessing an image packaged in the applet's own JAR file.
    One further detail: this "DOES NOT OCCUR" when there is a fast connection to the server (or at leat it seems so). In these cases, the JAR file is downloaded once. It looks as if the problem only occurs on slower network connections.
    Thanks in advance for any help.

    Mmm... I don't think this is the solution... all the applets share a lot of classes (the big part of the JAR files).
    But my question is....: why in some cases the JAR is downloaded more than once???

  • [Struts] Reload the same page but scroll automatically to where it was

    Hi,
    I have a form and it is quite long with a vertical scroll bar. Now when the user scrolls down and changes a value, I need to reload the same form with other values and display it to the user. When the form reloads, it should not show the top of the page as if it were accessed for the first time. It should automatically scroll down to the position where the user left. I think this can happen, but I am not able to work this out.. Please help. In order to reload the form, I am using
    new ActionForward( mapping.getInput() )
    Thanks
    SJ

    Is there still a search engine selected?
    You can click the search engines icon on the search bar and open Manage Search Engines.<br />
    You may need to click the Restore Defaults button to restore missing search engines.

  • HT1399 How can I see that I already have a song on my Ipod and review my full list of songs all together? So I don't reload the same song.

    How can I see that I already have a song on my Ipod and review my full list of songs all together? So I don't reload the same song.

    In iTunes, try changing "album artist" tag to the same name for eack track,
    also make sure that "track number" values are correct and different for each.
    (select all songs of an album > lmb > get info)

  • Deploying 2 entity beans in the same jar file using jboss

    i have beans namely savings entity bean, checkings entity beans and teller session beans, i'm trying to deploy it with in the same jar file. but im getting an error 'savings bean : bean expects one persistance-type'. i hope someone could help me about this. its urgent. thanks

    Although I am not super familiar with Jboss, my guess is that looks like the ejb xml sheet is not specifying the persistance type correctly for an entity bean. Take a look at your ejb xml sheet or post it if necessary.
    -Dat

  • Why does the back arrow just reload the same page most of the time

    why does the back arrow just reload the same page most of the time
    == This happened ==
    Not sure how often
    == most of the time since I installed it

    Hi Keith.
    This is probably a normal behavior that's induced by the way pages are done. Can you provide a link to a page where this happens?
    For example, wikipedia articles often have links that lead to sections of the article and not to actually different pages, as you may know. If you click the Back button, Firefox will lead you to the section of the page you were looking at when you clicked that link. Is this perhaps what you're talking about?
    AJAX pages (i.e. pages that take advantage of heavy duty javascript code and server side technologies) often have troubles like these. It's very hard to prevent this from happening from the browsers' point of view, but Mozilla is trying to find a way for Firefox 4 (at least like time I checked they were). So using the back and forth buttons in gmail will probably be troublesome.

  • How to use two different versions of the same jar within one project

    Hi everybody!
    I have a big problem while integrating different web service clients within one bigger java project. Both implemetations need some jar files to work but demand different version. So, i would like to know if there is any way to tell which implementation should use which version! Anyhow i add those jars to the classpath makes working only one or the other webservice working but never both! Any ideas somebody?
    Best regrads,
    Stefan G�tz

    Of course do have the jar files different names but the classes inside of them are the same ... means that the standard system classloader can distinguish them. When you add a jar to a classpath the name actually dosent matter.... any other ideas, please?
    PD.: i tryed to add a manifest file to the one jar which makes use of one of the dublicated jars to specify which jar to take direcly but it makes no difference since once classes loaded they cant be distinguish ....see:
    http://java.sun.com/docs/books/tutorial/ext/basics/load.html

  • Reload the same page with multiple param id

    Hi dude,
    i create review.jsp and include the displayproduct.jsp.. when i add review for the particular product,value added succesfully in db and successurl method will call and reload the displayproduct.jsp as blank page.. because param id not passing in url..
    how to pass the previous navactionid,navcountid and productid to SuccessURL with same jsp..
    pls clarify my doubt..

    hi MishraI need to pass the param in button
    <dsp:input type="submit" bean="MyReviewFormHandler.addReview" value="Submit Review">
    <dsp:input bean="MyReviewFormHandler.ProductReviewSuccessURL" type="hidden" value="displayCategory.jsp" />
    >
    It should work.
    I'm using below same way and working fine.
    <%/* URL to go to if user's session expires while he is filling out this form */%>
         <dsp:input bean="ShoppingCartModifier.sessionExpirationURL" type="hidden" value="../../common/SessionExpired.jsp"/>
         <%/* ADD TO CART BUTTON: Adds this SKU to the Order*/%>
         <dsp:input bean="ShoppingCartModifier.addItemToOrder" type="submit" value="Add to Cart "/>
         <%/* Goto this URL if NO errors are found during the ADD TO CART button  processing:*/%>
         <dsp:input bean="ShoppingCartModifier.addItemToOrderSuccessURL" type="hidden"  value="../checkout/cart.jsp"/>-RMishra

  • When I click a button to open an online enrolment form, Firefox just reloads the same page.

    I've tried clicking on this link to a allow you to enrol to vote in Australia on my mac, but everytime I do it it just reloads the page. I've been able to open it in chrome and on firefox on a pc and from that I can gather it seems to be one of those separate web apps but I don't have java installed on either of my computers so it's not a java applet. This has happened before with other links to similar styles of interactive web apps but the same thing happens, it just reloads the page with the link on it. I always just ended up doing them on a different computer or browser. I tried disabling all add-ons and allowed all pop ups but that didn't solve it. I couldn't find anyone with similar problems when I searched.

    You can try these steps in case of issues with web pages:
    Reload web page(s) and bypass the cache to refresh possibly outdated or corrupted files.
    *Hold down the Shift key and left-click the Reload button
    *Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    *Press "Command + Shift + R" (Mac)
    Clear the cache and cookies only from websites that cause problems.
    "Clear the Cache":
    *Firefox > Preferences > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Firefox > Preferences > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe Mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • When in the middle of doing work Firefox just crashes, A sorry window pups up asking if user wants to Reload the same session or start a new session. This never happen with previous versions.

    Since I updated Firefox to the latest version it crashes a lot and although I can reload the session I was working with it is annoying and time consuming. I always keep my computer 100% updated and virus free as I always run Norton. I also have 4 G of RAM and 500 G disk drive so it is not lack of RAM and never keep more that 3 windows open at the same time.

    (1) Firefox's built-in post-crash page has not been a real HTML page for a long time (for example, from the time of Firefox 22, see: [https://support.mozilla.org/en-US/questions/968212 Want to save LOTS of versions of "Restore Session.xht" from the "oops ..." page for later use]). If you had this working differently with Firefox 25, that might have been created by an extension.
    You can check to see whether extensions are disabled or need an update on the Add-ons page. Either:
    * Ctrl+Shift+a
    * orange Firefox button (or Tools menu) > Add-ons
    In the left column, click Extensions. The disabled extensions cluster toward the bottom of the list. To poll for updates, use the "gear" button above the list and choose Check for Updates.
    If you used the Reset feature (or Firefox automatically did a reset due to some problem during upgrading), you will need to reinstall missing extensions. The reset feature creates a folder on the desktop named Old Firefox Data. Do you have that folder? There may be data you can recover from it.
    (2) There are many ways for history to get cleared, both internal to Firefox and external. Could you double-check your Privacy settings?
    orange Firefox button (or Tools menu) > Options > Privacy
    * The "Firefox will" drop-down says Remember History: Firefox shouldn't be clearing history, but an add-on or external software could do it
    * The "Firefox will" drop-down says Use custom settings for history: inspect the "Clear history when Firefox closes" setting to make Firefox isn't set to clear history. Also check your add-ons and consider external software.
    Firefox normally accumulates months of history. However, some of Firefox's database sizes are based on disk space available. If your hard drive is very full, Firefox might reduce the amount of history stored.

  • I keep getting the same error message:  "Runtime Error" for adobe reader

    Hi,
    I keep getting a 'Runtime Error' message stating the following:  "This application has requested the runtime to terminate it in an unusual way.  Please contact the applications server team for more information".  It then closes the attachment and shuts down the email program.  The email program that is being used is outlook express, I have tried removing Adobe and reinstalling it - with the same issue.  I have tried downloading earlier additions with the same issue.
    Any advice in relation to this issue would be greatly appreciated.
    Cheers,
    Janet

    You can go to control panel, add/delete programs and delete Quick time. Then download & install the stand alone version of Quicktime.
    http://www.apple.com/quicktime/download/

  • Reload the same viewController with different data?

    Hi -
    I have a view which can have either a list of, say, fruit, or fruit vendors. If it a list of vendors, clicking a vendor loads a view where it lists the fruit they sell. If it's a list of fruit, clicking a fruit loads a view where it lists all the vendors of that fruit.
    The same view controller controls that page no matter which set of data is displayed.
    What I'd like to do is animate the transition when that click takes place just like I was going to a different view controller.
    I tried this:
    [[self navigationController] pushViewController:self animated:YES];
    But it's not doing anything - at all.
    Is there a way to do this short of rewriting it to have two separate view controllers for the two sets of data?
    (Sorry, posted this in the wrong forum and I don't see a way to delete it here...)
    Message was edited by: Sue Boettcher1

    Well, I spoke too soon.
    I can get the page to load and it animates right, but I think I haven't got it hooked up right in the nib "referencing outlet" stuff correctly.
    I can't get my head around it - I have to create a new instance of the view INSIDE a method for the view itself. I can see where the other (original) instance of the view is hooked up in the nib but I can't figure out how to hook up the new second instance.
    I'm probably not explaining this very well but I can't post a screenshot...

  • Reload the same Image every second

    Has anyone load an Image and refreshed it automatically?
    What I would like to do is....
    1. Load Image on document creation.
    2. Refresh the image every 100 ml secs
    3. Its the same image.... another app that we wrote writes
    over the original
    thanks in advance
    This doesn't work at all
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    initialize="initTimer()">
    <mx:Script><![CDATA[
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    public function initTimer():void {
    // The first parameter is the interval (in milliseconds).
    The
    // second parameter is number of times to run (0 means
    infinity).
    var myTimer:Timer = new Timer(1000, 0);
    myTimer.addEventListener("timer", timerHandler);
    myTimer.start();
    public function timerHandler(event:TimerEvent):void {
    var url:String = "
    http://localhost/frame.png";
    var urlReq:URLRequest = new URLRequest(url);
    framePNG.url= sURL; //to avoid caching
    framePNG.send();
    ]]>
    </mx:Script>
    <mx:Image id="framePNG" />
    </mx:Application>

    OK - my guess is that it was to randomize the url to prevent
    caching. As much as I don't like the workaround, try something like
    this: take away your sURL and make it correctly load the image
    once.
    Once this is working, try to set the url like this:
    var url:String = "
    http://localhost/frame.png?dummy="
    + (new Date()).time;
    trace(url); // Just so you can make sure it changes every
    time
    What this is doing is changing your url every time it's
    requested so it's never found in the cache. Perhaps the cleaner way
    of doing this is correcting your server so the headers set
    immediate expiration.

  • Reloading the same image into a JPanel

    I have a multi user app.. one user can edit an image in one GUI and i want the other user to be able to refresh somehow a JPanel that they have in their GUI to reload the image file.
    any help, would be appreciated.
    thanks

    Send a signal from one user's frame to the other's to reload the image. Then just call setIcon as you did before.

  • When i try to reload the same data what will happen in my ods?

    Hi all,
    Someone has already loaded the data from flat file into the respective ods.
    for instance:
    customer number customer name cust address
       10001          xav          123
       10002          xac           234
    And this has been loaded by some one else.
    If i am going to load the same data in the ods. will it create 2 entries nor just going to be only one entry.
    i meant will it be like this
    customer number customer name cust address
       10001          xav           123
       10002          xac           234
       10001          xav           123
       10002          xac           234
    nor like this
    customer number customer name cust address
       10001          xav          123
       10002          xac           234.
    Thanxs
    Haritha

    Hi,
    If two Records of same key combination is there then over writing will happn in ODS. Within the request overwriting is done in the updation(from change log table to active data table). Within different request overwriting is done during activation(new data table to change log table) Zero record mode is doing this.
    read this along with other replies
    Thanks and regards
    Obily

Maybe you are looking for

  • How do I make a PDF read only in Pro 9 extended

    Hello, I created a document in Adobe presenter and published a PDF file. I'm using the file in a LearninIg Management System where students can take courses online. I want the student to be able to open the PDF in the browser without the save or prin

  • Neo2: many winxp install problems, but is this my solution?

    Well I have just assembled the parts shown in my sig, except without the western digital HDD. I have only the single SATA drive connected. I have run into some problems installing windows xp pro. I get a NTLDR message, or if I manage to get into setu

  • RAW plug-ins for Leica V-Lux 4 camera, .RWL files

    I am using Photoshop CS4 on a Mac Pro, OS 10.7.5. I own a Leica V-Lux 2 camera which records RAW files as .RWL files. PS CS4 won't open the  .RWL files even tho Adobe Updater  tells me that I am up-to-date. I can't find anywhere on the Adobe website

  • Magic number mismatch: bad mzip file in 3750 stack switch

    Hi All can anybody help me in this error msg "magic number mismatch: bad mzip file" I am trying to upgrade the switch  with"c3750e-ipbasek9-tar.122-55.SE5.tar" in 3750 stack switch it is  showing this error msg while booting thanks in advance

  • Creating Globally Reusable 2013 Workflows on SharePoint Designer 2013

    I'd like to create a workflow for a list in an application I downloaded from the Office store. The option I have is to create a globally reusable workflow which I can then use on the applications list. How can I create a globally reusable 2013 workfl