how to run a jar, from another jar.

Discussion in 'Java' started by tiewknvc9, Sep 30, 2006.

  1. tiewknvc9

    tiewknvc9 Guest

    Hi.

    As the subject suggests. I am trying to run an application bundled in a
    jar1 file, the from that jar1 file, I would like to run the jar2 file
    and close jar1.

    The idea is that jar1 is an updater and will check online and install
    updates to jar2, then jar2 (the main app) will start up, close jar1,
    and update jar1 (if neccessary). The thing that Im struggling with is
    how to actually run the jar2 file.

    Thanks for your help!
    tiewknvc9, Sep 30, 2006
    #1
    1. Advertising

  2. tiewknvc9

    hiwa Guest

    tiewknvc9 wrote:
    > Hi.
    >
    > As the subject suggests. I am trying to run an application bundled in a
    > jar1 file, the from that jar1 file, I would like to run the jar2 file
    > and close jar1.
    >
    > The idea is that jar1 is an updater and will check online and install
    > updates to jar2, then jar2 (the main app) will start up, close jar1,
    > and update jar1 (if neccessary). The thing that Im struggling with is
    > how to actually run the jar2 file.
    >
    > Thanks for your help!

    What's the problem you pesume?
    hiwa, Sep 30, 2006
    #2
    1. Advertising

  3. tiewknvc9

    Ben_ Guest

    Open jar2's manifest file, look at the main class defined and invoke its
    main method using the reflection API (see java.lang.Class and
    java.lang.reflect.Method).
    Ben_, Sep 30, 2006
    #3
  4. tiewknvc9

    Jeff Guest

    Check out URLClassLoader (or ClassLoader, and pick which one works best
    for your application) to create an object of the desired class, then
    your java.lang.reflect,Method routines to execute the desired method.

    Ben_ wrote:
    > Open jar2's manifest file, look at the main class defined and invoke its
    > main method using the reflection API (see java.lang.Class and
    > java.lang.reflect.Method).
    Jeff, Sep 30, 2006
    #4
  5. tiewknvc9

    tiewknvc9 Guest

    Jeff wrote:
    > Check out URLClassLoader (or ClassLoader, and pick which one works best
    > for your application) to create an object of the desired class, then
    > your java.lang.reflect,Method routines to execute the desired method.
    >
    > Ben_ wrote:
    > > Open jar2's manifest file, look at the main class defined and invoke its
    > > main method using the reflection API (see java.lang.Class and
    > > java.lang.reflect.Method).


    ok, I imported the 2 classes JarRunner and JarClassLoader/

    and it works... to a degree.

    It does seem to load the main class! (hooray!), and try to run the
    application, however Im having a strange problem... The 2nd jar, is
    having trouble loading the images that are packaged inside the 2nd jar!

    It reports a nullPointerException when it is trying to load an image...
    Im using the standard

    Image img=
    getToolkit().getImage(ClassLoader.getSystemResource(m_strImage));

    what am I doing wrong?
    tiewknvc9, Oct 1, 2006
    #5
  6. tiewknvc9

    Jeff Guest

    tiewknvc9 wrote:
    > Jeff wrote:
    > > Check out URLClassLoader (or ClassLoader, and pick which one works best
    > > for your application) to create an object of the desired class, then
    > > your java.lang.reflect,Method routines to execute the desired method.
    > >
    > > Ben_ wrote:
    > > > Open jar2's manifest file, look at the main class defined and invoke its
    > > > main method using the reflection API (see java.lang.Class and
    > > > java.lang.reflect.Method).

    >
    > ok, I imported the 2 classes JarRunner and JarClassLoader/
    >
    > and it works... to a degree.
    >
    > It does seem to load the main class! (hooray!), and try to run the
    > application, however Im having a strange problem... The 2nd jar, is
    > having trouble loading the images that are packaged inside the 2nd jar!
    >
    > It reports a nullPointerException when it is trying to load an image...
    > Im using the standard
    >
    > Image img=
    > getToolkit().getImage(ClassLoader.getSystemResource(m_strImage));
    >
    > what am I doing wrong?


    There are issues with using ClassLoader, in that there are multiple
    versions that will look at different locations for loading the class in
    question. Best source to understand this is a white paper on
    Class.forName - see
    http://www.theserverside.com/tt/articles/content/dm_classForname/DynLoad.pdf
    Jeff, Oct 1, 2006
    #6
  7. tiewknvc9

    tiewknvc9 Guest

    Jeff wrote:
    > tiewknvc9 wrote:
    > > Jeff wrote:
    > > > Check out URLClassLoader (or ClassLoader, and pick which one works best
    > > > for your application) to create an object of the desired class, then
    > > > your java.lang.reflect,Method routines to execute the desired method.
    > > >
    > > > Ben_ wrote:
    > > > > Open jar2's manifest file, look at the main class defined and invoke its
    > > > > main method using the reflection API (see java.lang.Class and
    > > > > java.lang.reflect.Method).

    > >
    > > ok, I imported the 2 classes JarRunner and JarClassLoader/
    > >
    > > and it works... to a degree.
    > >
    > > It does seem to load the main class! (hooray!), and try to run the
    > > application, however Im having a strange problem... The 2nd jar, is
    > > having trouble loading the images that are packaged inside the 2nd jar!
    > >
    > > It reports a nullPointerException when it is trying to load an image...
    > > Im using the standard
    > >
    > > Image img=
    > > getToolkit().getImage(ClassLoader.getSystemResource(m_strImage));
    > >
    > > what am I doing wrong?

    >
    > There are issues with using ClassLoader, in that there are multiple
    > versions that will look at different locations for loading the class in
    > question. Best source to understand this is a white paper on
    > Class.forName - see
    > http://www.theserverside.com/tt/articles/content/dm_classForname/DynLoad.pdf



    ok, now I am able to load the class! Sweet!

    But it still doesn't run, because it cannot find the images stored in
    the very same jar file....

    the jar file is on the classpath, and I do use the
    ClassLoader.getSystemResource(strFile) to read the file from the main
    function... so why isn't it finding the images?

    If I run the jar by itself, it runs perfectly. However when I run the
    main class of that jar from another jar, it cannot find the images....
    I hope its something simple to correct.... any ideas?
    tiewknvc9, Oct 1, 2006
    #7
  8. tiewknvc9

    Jeff Guest

    tiewknvc9 wrote:
    > Jeff wrote:
    > > tiewknvc9 wrote:
    > > > Jeff wrote:
    > > > > Check out URLClassLoader (or ClassLoader, and pick which one works best
    > > > > for your application) to create an object of the desired class, then
    > > > > your java.lang.reflect,Method routines to execute the desired method.
    > > > >
    > > > > Ben_ wrote:
    > > > > > Open jar2's manifest file, look at the main class defined and invoke its
    > > > > > main method using the reflection API (see java.lang.Class and
    > > > > > java.lang.reflect.Method).
    > > >
    > > > ok, I imported the 2 classes JarRunner and JarClassLoader/
    > > >
    > > > and it works... to a degree.
    > > >
    > > > It does seem to load the main class! (hooray!), and try to run the
    > > > application, however Im having a strange problem... The 2nd jar, is
    > > > having trouble loading the images that are packaged inside the 2nd jar!
    > > >
    > > > It reports a nullPointerException when it is trying to load an image...
    > > > Im using the standard
    > > >
    > > > Image img=
    > > > getToolkit().getImage(ClassLoader.getSystemResource(m_strImage));
    > > >
    > > > what am I doing wrong?

    > >
    > > There are issues with using ClassLoader, in that there are multiple
    > > versions that will look at different locations for loading the class in
    > > question. Best source to understand this is a white paper on
    > > Class.forName - see
    > > http://www.theserverside.com/tt/articles/content/dm_classForname/DynLoad.pdf

    >
    >
    > ok, now I am able to load the class! Sweet!
    >
    > But it still doesn't run, because it cannot find the images stored in
    > the very same jar file....
    >
    > the jar file is on the classpath, and I do use the
    > ClassLoader.getSystemResource(strFile) to read the file from the main
    > function... so why isn't it finding the images?
    >
    > If I run the jar by itself, it runs perfectly. However when I run the
    > main class of that jar from another jar, it cannot find the images....
    > I hope its something simple to correct.... any ideas?


    Try using URLClassLoader. With that you can specify exactly where the
    loader should look for the class or info. You can test it to be sure it
    finds it by using the findResource method.
    Jeff, Oct 2, 2006
    #8
  9. tiewknvc9

    tiewknvc9 Guest

    for those of you who have been searching for the answer..... do this!

    cmd = "javaw -jar jar2.jar";

    Process proc = Runtime.getRuntime().exec(cmd);


    tiewknvc9 wrote:
    > Jeff wrote:
    > > tiewknvc9 wrote:
    > > > Jeff wrote:
    > > > > Check out URLClassLoader (or ClassLoader, and pick which one works best
    > > > > for your application) to create an object of the desired class, then
    > > > > your java.lang.reflect,Method routines to execute the desired method.
    > > > >
    > > > > Ben_ wrote:
    > > > > > Open jar2's manifest file, look at the main class defined and invoke its
    > > > > > main method using the reflection API (see java.lang.Class and
    > > > > > java.lang.reflect.Method).
    > > >
    > > > ok, I imported the 2 classes JarRunner and JarClassLoader/
    > > >
    > > > and it works... to a degree.
    > > >
    > > > It does seem to load the main class! (hooray!), and try to run the
    > > > application, however Im having a strange problem... The 2nd jar, is
    > > > having trouble loading the images that are packaged inside the 2nd jar!
    > > >
    > > > It reports a nullPointerException when it is trying to load an image...
    > > > Im using the standard
    > > >
    > > > Image img=
    > > > getToolkit().getImage(ClassLoader.getSystemResource(m_strImage));
    > > >
    > > > what am I doing wrong?

    > >
    > > There are issues with using ClassLoader, in that there are multiple
    > > versions that will look at different locations for loading the class in
    > > question. Best source to understand this is a white paper on
    > > Class.forName - see
    > > http://www.theserverside.com/tt/articles/content/dm_classForname/DynLoad.pdf

    >
    >
    > ok, now I am able to load the class! Sweet!
    >
    > But it still doesn't run, because it cannot find the images stored in
    > the very same jar file....
    >
    > the jar file is on the classpath, and I do use the
    > ClassLoader.getSystemResource(strFile) to read the file from the main
    > function... so why isn't it finding the images?
    >
    > If I run the jar by itself, it runs perfectly. However when I run the
    > main class of that jar from another jar, it cannot find the images....
    > I hope its something simple to correct.... any ideas?
    tiewknvc9, Oct 2, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cyril
    Replies:
    2
    Views:
    3,835
    cyril
    Aug 25, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    554
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,688
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,725
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    638
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page