how to run a jar, from another jar.

T

tiewknvc9

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!
 
H

hiwa

tiewknvc9 said:
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?
 
B

Ben_

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).
 
J

Jeff

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.
 
T

tiewknvc9

Jeff said:
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.

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?
 
J

Jeff

tiewknvc9 said:
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
 
T

tiewknvc9

Jeff said:
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?
 
J

Jeff

tiewknvc9 said:
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.
 
T

tiewknvc9

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

cmd = "javaw -jar jar2.jar";

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top