This discussion is archived
5 Replies Latest reply: Jun 25, 2012 5:18 AM by 939520 RSS

How to load jar file in one shot?

945341 Newbie
Currently Being Moderated
I have a Java app refers some jar files on remote location. Loading class by class is very time consuming.

Is it possible to load the jar files as a whole? like what applet does?

Tried URLClass loading, even run java -jar, still those load class on demand.

I want the jar file loaded only one time into JVM.
  • 1. Re: How to load jar file in one shot?
    sabre150 Expert
    Currently Being Moderated
    I don't really understand. When you load a jar file using URLClassLoader it brings over the jar file and extracts the class files from the jar file. It does not bring over the class files as individual class files. If you mean you want to only ever bring over the jar file once then why not just copy the jar file using URLConnection and save it to disk. You can then load the jar file from disk each time the program starts.
  • 2. Re: How to load jar file in one shot?
    939520 Explorer
    Currently Being Moderated
    I don't know if this will help, but Maven handles such transitive dependencies for jar files. Your may consider using Maven for your projects. See
    http://www.avajava.com/tutorials/lessons/how-do-i-add-a-transitive-dependency-to-my-projects-classpath.html
  • 3. Re: How to load jar file in one shot?
    945341 Newbie
    Currently Being Moderated
    Is that true? when loading a jar file using URLClassLoader it brings over the jar file and extracts the class files from the jar file?

    Does System class loader extends from URLClassLoader?

    Thanks
  • 4. Re: How to load jar file in one shot?
    sabre150 Expert
    Currently Being Moderated
    942338 wrote:
    Is that true? when loading a jar file using URLClassLoader it brings over the jar file and extracts the class files from the jar file?
    What active agent on a server will first unzip the jar file before sending over the individual class file? Any why would it do that?
  • 5. Re: How to load jar file in one shot?
    939520 Explorer
    Currently Being Moderated
    As I understand it, when you add a jar file to your project and add it to your classpath its ready to be used by your application. There is no need to manually unzip and/or load the classes. I don't think you will gain any significant performance advantage to manually loading them all compared to letting The JVM handle that for you. Perhaps I'm missing something in your question. Why do you want to manually load them?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points