Executing a jar file  
Author Message
steve





PostPosted: 2004-7-18 0:28:00 Top

java-programmer, Executing a jar file I have the following code
/*

WinTest.java

*/

import java.io.*;


public class WinTest {
public static void main (String args[]) {

String line;
Process backgroundProcess;

try {

// Start the other process
backgroundProcess = Runtime.getRuntime().exec
("d:\\program files\\cprog.exe");
}
catch (Exception e) {

System.out.println(e);
}
}
}


If I execute the class file from a cmd windown I get the start up
screen from the cprog.exe, however as I would like to dispense with
the dos window I packaged the class into a jar file

First creating a text file called WinTest.txt containin the single
line

Main-Class: WinTest

Then create the jar file

jar cmf WinTest app.jar WinTest.class

I associated the jar file with the java.exe in the SDK lib

But when I double click to execute the jar file a dos window pops up
disappears but no start screen from the cprog.exe is shown

I'm sure it is a severe user error must I have to admit to being
stumped and help would be nuch appreciated
 
Chad J McQuinn





PostPosted: 2004-7-18 4:32:00 Top

java-programmer >> Executing a jar file In article <email***@***.com>,
email***@***.com (Che) wrote:

> I associated the jar file with the java.exe in the SDK lib
>
> But when I double click to execute the jar file a dos window pops up
> disappears but no start screen from the cprog.exe is shown

I don't know if the tools work the same on windows (I assume they do),
but on unix you execute such a file with the command "java -jar
file.jar". So I guess on windows maybe you need to add the "/jar" switch?

-Chad
 
Michael Cox





PostPosted: 2004-7-19 0:29:00 Top

java-programmer >> Executing a jar file >So I guess on windows maybe you need to add the "/jar" switch?

no it's "java -jar File.jar" on windows as well




 
 
Raymond DeCampo





PostPosted: 2004-7-19 4:11:00 Top

java-programmer >> Executing a jar file Che wrote:
>
> I associated the jar file with the java.exe in the SDK lib
>
> But when I double click to execute the jar file a dos window pops up
> disappears but no start screen from the cprog.exe is shown
>
> I'm sure it is a severe user error must I have to admit to being
> stumped and help would be nuch appreciated

Open a DOS prompt in the directory containing your jar file. Enter the
jar file as if it were a command. This will execute the jar file in the
same manner as double-clicking. The difference is that the DOS window
will not immediately disappear and you may get some useful information.

HTH,
Ray

--
XML is the programmer's duct tape.
 
 
Michael Cox





PostPosted: 2004-7-20 23:22:00 Top

java-programmer >> Executing a jar file
"Raymond DeCampo" <email***@***.com> wrote in
message news:vPAKc.49099$email***@***.com...
> Che wrote:
> >
> > I associated the jar file with the java.exe in the SDK lib
> >
> > But when I double click to execute the jar file a dos window pops up
> > disappears but no start screen from the cprog.exe is shown
> >
> > I'm sure it is a severe user error must I have to admit to being
> > stumped and help would be nuch appreciated
>
> Open a DOS prompt in the directory containing your jar file. Enter the
> jar file as if it were a command. This will execute the jar file in the
> same manner as double-clicking. The difference is that the DOS window
> will not immediately disappear and you may get some useful information.

Or for the above you can change javaw.exe to java.exe under
explorer|tools|file type extensions| jar|edit ...

Gives the same result.



 
 
doodpants





PostPosted: 2004-7-21 2:04:00 Top

java-programmer >> Executing a jar file email***@***.com (Che) wrote in message news:<email***@***.com>...

> I associated the jar file with the java.exe in the SDK lib
>
> But when I double click to execute the jar file a dos window pops up
> disappears but no start screen from the cprog.exe is shown

The .jar extension should be associated with javaw.exe. You shouldn't
get a dos window at all this way, even for a split second. In fact,
when you installed the Java SDK, this association should have been
made automatically by the installer.

I don't know if changing this will fix the problem of cprog.exe not
being launched, though.