Running an Executable Before Executable JAR

J

Jason Cavett

Is it possible to run an executable prior to the execution of a JAR
file? Currently, I am doing this via a batch file, but, my customer
only wants to click on the JAR file and have everything run
(additional external executable first, then JAR).

I haven't found anything online, although I'm not sure I'm searching
for the correct terminology.

Thanks for any help.
 
E

Eric Sosman

Jason said:
Is it possible to run an executable prior to the execution of a JAR
file? Currently, I am doing this via a batch file, but, my customer
only wants to click on the JAR file and have everything run
(additional external executable first, then JAR).

I haven't found anything online, although I'm not sure I'm searching
for the correct terminology.

How about having the batch file end with

java -jar ...

.... and telling the customer to launch the batch file
(only) instead of the JAR?
 
P

Phi

Jason said:
Is it possible to run an executable prior to the execution of a JAR
file? Currently, I am doing this via a batch file, but, my customer
only wants to click on the JAR file and have everything run
(additional external executable first, then JAR).

I haven't found anything online, although I'm not sure I'm searching
for the correct terminology.

Thanks for any help.

Hi Jason

What about telling the OS (eg. windows / linux / macOS) that JAR-files
should be executable (using java -jar or javaw) by clicking on them.
On Windows this is the standard, when you install a new JRE.
Then simply make your manifest pointing to your main class (MANIFEST.MF
= main-class: MyMain) and calling the external executable
from within the java-main()-method [using the
java.lang.Runtime.exec()-method]?
So actually your JVM is loaded first, starting your main(), then your
exe is executed and then the rest of your bytecode will be executed.

But probably I have not understood the "everything" correctly.

Actually, the way it is stated in your question, I think its logically
impossible:
- "the custommer only wants to click on the JAR file ...
This will make the jar run first!
Except you have a link on your desktop which is called XYZ.jar and
actually points to a batch or exe-file ;-)
- ... and have everyting (whatever this is but including the JAR) run"
This will run your exe and (", then JAR"), which will call itself
recursively?
Does your customer realy mean, that the jar (which he clicked at the
beginning) has to be executed again?

Greets phi
 
S

Sherm Pendley

Phi said:
What about telling the OS (eg. windows / linux / macOS) that JAR-files
should be executable (using java -jar or javaw) by clicking on them.
On Windows this is the standard, when you install a new JRE.

That's standard on Mac OS X too, although most folks take the extra step
of bundling the .jar into a .app bundle if they have a lot of Mac users.
That way they can specify the icon, associate document extensions, etc.
that you don't get with a generic .jar.

sherm--
 
P

Phi

Sherm said:
That's standard on Mac OS X too, although most folks take the extra step
of bundling the .jar into a .app bundle if they have a lot of Mac users.
That way they can specify the icon, associate document extensions, etc.
that you don't get with a generic .jar.

sherm--

Hi Sherm

Thanks for competion, when I was a mac user years ago, there was no Java
around (1985)...

The issue of bundling a jar into an application seams to be different on
every platform. I don't think that it is pure a Java issue, but an OS
issue as well.
Probably we should know, on which OS our friend Jason wants to execute
his application. If it's on Gnome (linux), I have some knowledge on
making "application starters"...

phi
 
J

Jason Cavett

How about having the batch file end with

java -jar ...

... and telling the customer to launch the batch file
(only) instead of the JAR?

This is the way it was originally done. However, the customer doesn't
like the batch file window staying open in the background. Haha,
small problem I know, but it kind of made me curious if it could even
be done.
 
J

Jason Cavett

Jason said:
Is it possible to run an executable prior to the execution of a JAR
file? Currently, I am doing this via a batch file, but, my customer
only wants to click on the JAR file and have everything run
(additional external executable first, then JAR).
I haven't found anything online, although I'm not sure I'm searching
for the correct terminology.
Thanks for any help.

Hi Jason

What about telling the OS (eg. windows / linux / macOS) that JAR-files
should be executable (using java -jar or javaw) by clicking on them.
On Windows this is the standard, when you install a new JRE.
Then simply make your manifest pointing to your main class (MANIFEST.MF
= main-class: MyMain) and calling the external executable
from within the java-main()-method [using the
java.lang.Runtime.exec()-method]?
So actually your JVM is loaded first, starting your main(), then your
exe is executed and then the rest of your bytecode will be executed.

But probably I have not understood the "everything" correctly.

Actually, the way it is stated in your question, I think its logically
impossible:
- "the custommer only wants to click on the JAR file ...
This will make the jar run first!
Except you have a link on your desktop which is called XYZ.jar and
actually points to a batch or exe-file ;-)
- ... and have everyting (whatever this is but including the JAR) run"
This will run your exe and (", then JAR"), which will call itself
recursively?
Does your customer realy mean, that the jar (which he clicked at the
beginning) has to be executed again?

Greets phi

I'm on a Windows system.

And, yeah, they basically don't want to see the batch file window (see
post above). I *could* do the Runtime.exec (or Process), but the
location of the executable file is not static, so then I'd have to set
it up as a config.

Either way, I also agree that this may not be possible. That's why I
wanted to ask the brains here and see if anybody knew of any way to
accomplish the task.
 
R

Richard Reynolds

Jason Cavett said:
Jason said:
Is it possible to run an executable prior to the execution of a JAR
file? Currently, I am doing this via a batch file, but, my customer
only wants to click on the JAR file and have everything run
(additional external executable first, then JAR).
I haven't found anything online, although I'm not sure I'm searching
for the correct terminology.
Thanks for any help.

Hi Jason

What about telling the OS (eg. windows / linux / macOS) that JAR-files
should be executable (using java -jar or javaw) by clicking on them.
On Windows this is the standard, when you install a new JRE.
Then simply make your manifest pointing to your main class (MANIFEST.MF
= main-class: MyMain) and calling the external executable
from within the java-main()-method [using the
java.lang.Runtime.exec()-method]?
So actually your JVM is loaded first, starting your main(), then your
exe is executed and then the rest of your bytecode will be executed.

But probably I have not understood the "everything" correctly.

Actually, the way it is stated in your question, I think its logically
impossible:
- "the custommer only wants to click on the JAR file ...
This will make the jar run first!
Except you have a link on your desktop which is called XYZ.jar and
actually points to a batch or exe-file ;-)
- ... and have everyting (whatever this is but including the JAR) run"
This will run your exe and (", then JAR"), which will call itself
recursively?
Does your customer realy mean, that the jar (which he clicked at the
beginning) has to be executed again?

Greets phi

I'm on a Windows system.

And, yeah, they basically don't want to see the batch file window (see
post above). I *could* do the Runtime.exec (or Process), but the
location of the executable file is not static, so then I'd have to set
it up as a config.

Either way, I also agree that this may not be possible. That's why I
wanted to ask the brains here and see if anybody knew of any way to
accomplish the task.
would the windows "start" command do your job?

I vaguely remember using it, think it starts a process for you and
disconnects it from the cmd window letting it close so maybe you could use
it at the end of your batch file to start up the jvm using javaw?
 
S

Sanjay

I'm on a Windows system.

And, yeah, they basically don't want to see the batch file window (see
post above). I *could* do the Runtime.exec (or Process), but the
location of the executable file is not static, so then I'd have to set
it up as a config.

Either way, I also agree that this may not be possible. That's why I
wanted to ask the brains here and see if anybody knew of any way to
accomplish the task.


I haven't done it, so I am not sure it will work. Can you create a small
VB or C# program that runs your jar and then compile it as executable?
Thais way even if you have to open a command prompt you can hide it.
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top