0

I have a .java console application with no GUI. What script or commands would I need to compile and run it with arguments from the command prompt? I want to have the script run nightly from Task Scheduler, but I've been relying on Eclipse to run my Java code so far.

user3808188
  • 557
  • 2
  • 8
  • 20

2 Answers2

1

To compile a java application, use the javac command. To actually run the program, use the java command (after running the javac command).

For example (assuming you have a file named Driver.java):

javac Driver.java

(creates Driver.class file)

java Driver arg0 arg1 arg2

(runs the Driver program with arg0 arg1 and arg2 as command line arguments)

  • Do I have to compile it every time? Or can I just call the "java" command on Driver.class after the first time? – user3808188 Aug 14 '14 at 17:32
0

You can create a runnable jar file with Eclipse. Select File -> Export from the menu and then start the Runnable Jar File wizzard. You can select the launch configuration that you usually use to start your application. Then you also select the location and name of the jar file, where your application is exported.

To run the application from the console, you just use the command

java -jar exported-jar-file.jar
Jack
  • 2,937
  • 5
  • 34
  • 44