user1182836
user1182836

Reputation: 13

Batch file for compiling and running java files?

I'm trying to create a drag and drop shortcut for compiling and running java files, rather than a command line interface. I'm thinking, I will create two batch files. But, what do I write to make the batch files use javac.exe or java.exe on what ever java files are dropped onto the batch files?


For the compiler batch file:

cd C:\Program Files\Java\jdk\bin     
javac [what goes here?]    
pause

For the run java batch file:

cd C:\Program Files\Java\jdk\bin
java [what goes here?]
pause

Upvotes: 1

Views: 2733

Answers (2)

souliaq
souliaq

Reputation: 46

If you want to compile a single file this script will be useful.

Upvotes: 1

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81694

Don't bother; you would find these batch files useful for about one day. After that, your Java programs will contain multiple *.java files and depend on various *.jar files. Learn to use Ant, which can handle build processes from the simplest to the most complex.

But for completeness, the files DnD'd onto a batch file are available as if they were passed as arguments to the batch file at the command line, so your "[what goes here?]" is "%1", or, if you anticipate multiple files, "%1 %2 %3 %4 %5 %6 %7 %8 %9" .

Upvotes: 5

Related Questions