Running a Jar executable

Feb 2, 2008 at 3:53am

Running a Jar executable

I have looked around the forum and I could not really find this. I need a way to open a jar executable (a simple swing app) . For instance. I want just a simple class which extends MaxObject (obviously) that has one “bang” input which opens up a jar executable of a swing java application I wrote. Should I try to use something like Runtime.exec()? Also, I have written small swing interfaces using Max before and I remember having to use SwingUtilities.invokeLater(), will I have to incorporate this as well.

#35621
Feb 5, 2008 at 1:09am

Quote: Benjamin wrote on Fri, 01 February 2008 19:53
—————————————————-
> I have looked around the forum and I could not really find this. I need a way to open a jar executable (a simple swing app) . For instance. I want just a simple class which extends MaxObject (obviously) that has one “bang” input which opens up a jar executable of a swing java application I wrote. Should I try to use something like Runtime.exec()? Also, I have written small swing interfaces using Max before and I remember having to use SwingUtilities.invokeLater(), will I have to incorporate this as well.
—————————————————-

Hi Benjamin,
Yes, you could do Runtime.exec(). But if you have a jar file, why not add it to the Max classpath and call into the code directly from your MaxObject? You should be able to call the main() method of the main class. If you are not sure which is the main class, unzip the jar, find its manifest file, and look for the “Main-Class” setting.

If you really want/need to exec the jar, you could use one of the shell objects (search for “shell” on maxobjects.com) instead of making your own object to do the exec.

I haven’t coded in Swing in a while, but I believe you should always use invokeLater or invokeAndWait. Sun’s tutorials have more info: http://java.sun.com/docs/books/tutorial/uiswing/concurrency/initial.html
You only need to worry about this for the actual Swing code, not the exec call.

-Adam

#121610
Feb 5, 2008 at 1:42am

Hi Adam & Benjamin,

If the Swing stuff is to run in the same JVM as mxj, on OS X, then it
has to be invokeLater() every time, due to bad cocoa-carbon mojo.

So, Benjamin, if your original code doesn’t do that, you’ll either need
to use Runtime.exec() or change it.


Owen

Adam Murray wrote:

> I haven’t coded in Swing in a while, but I believe you should always
> use invokeLater or invokeAndWait. Sun’s tutorials have more info:
> http://java.sun.com/docs/books/tutorial/uiswing/concurrency/initial.html
> You only need to worry about this for the actual Swing code, not the
> exec call.

#121611

You must be logged in to reply to this topic.