aspose file tools
The moose likes Java in General and the fly likes Is there possible using commands with directory to run a java app?    Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Is there possible using commands with directory to run a java app?    " Watch "Is there possible using commands with directory to run a java app?    " New topic
Author

Is there possible using commands with directory to run a java app?

David Wong
Greenhorn

Joined: Dec 31, 2007
Posts: 15
Hi, I wanna use a command to run a JAVA application like C/C++, for instance, under the windows comand line I write instructions as below:

c:\>F:\MyVcApplications\test.exe

how can I run a java app like that?

c:\>java F:\MyJavaApplications\Test

I know the implementing as above is impossible. There may be a package can resolve this problem, write a line in JAVA code at head: package myjavaapplications; and run it like java myjavaapplications.Test

But this only resolved a part of the problems. How could I find a certain disk, F:\. Maybe you say just change the directory using cd instruction. But the point is I will implement the things in a program like this:

ProcessBuilder pb = new ProcessBuilder();
pb.command(/*the instructions will be here*/);

I think one way that use cd command in pb.command(), But I really prefer a concise way, this is little diffuse, I won't try it anyway.Please help me.

Thanks and wishes with the best.


Bitter Java For Better Life.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32712
    
    4
You probably can do that; find the article by Michael Daconta entitled "When Runtime.exec() won't" (easy on Google) which explains how to keep the two streams "empty."
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

For the part of your question about "run it from a command line".
Could an executable jar be a solution??

Or you can package your java code into an EXE-file JSmooth - Java Executable Wrapper


Regards, Rene Larsen
Dropbox Invite
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

Either (1) use the "-cp" switch to set the class path for the Java executable, or (2) create a batch file in which you run the program, including either the -cp switch or a "set CLASSPATH" command, and run that from your Java program.

Moving to "Intermediate."


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Is there possible using commands with directory to run a java app?
 
Similar Threads
Executing jar file - Urgent (Max Help)
J2SE 5
Cannot run .jar file
Package Java app that uses MySQL
Runtime.getRuntime().exec(commandToExecute) without promting for enter key to be pressed