How to tell if a java application was invoked with 'java' or 'javaw'

M

Michael

Is it possible for a 'main' function to tell if java was invoked with
'java' or 'javaw'?

Thanks,
 
A

Andrew Thompson

Is it possible for a 'main' function to tell if java was invoked with
'java' or 'javaw'?

Sure, feed it an argument.

But what about if it's invoked by double clicking a Jar file, or by JWS?
What if it is instantiated by an applet?

What is the actual problem you are trying to solve here?
What do you hope to achieve by knowing?
 
B

Boudewijn Dijkstra

Michael said:
Is it possible for a 'main' function to tell if java was invoked with
'java' or 'javaw'?

It could be that the standard streams are different.
 
M

Michael

The 'main' method needs to know if it can use System.out or not.
There are at least three alternatives:

- Have two differnet 'main' methods.
- Use a command line argument.
- Have the 'main' method figure it out.

The first two options require more cooperation from the user.
 
A

Andrew Thompson

...
The 'main' method needs to know if it can use System.out or not.

It can, in every circumstance.
java, javaw, jar/no jar, JWS, applet..

You can redirect the System.error and System.out to a file
and throw it up in a JOptionPane if it is all so fired
important to the user.

But if this information is so vital to the end user, why
are you writing it it System.out in the first place?

[ ..and please quote a little of what you are replying to,
to supply a context to the reader. ]
 

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,564
Members
45,040
Latest member
papereejit

Latest Threads

Top