• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
David Wong
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 56596
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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."
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!