Creating a macro command to run a program

I have a file Main.javaand I want to run the program by passing test.txt to it

I know on the command line, I can write javac Main.java

After compilation, I can write java Main test.txtand this will execute the file launch and going throughtest.txt

If I just wanted to write main test.txtand run this launch of my file Main.classfor this, and if so, how?

+5
source share
3 answers

(Edit: based on your comment, let me expand to add a couple more situations)

, - , Java, , Java, , , .class .jar . , : java- . , ​​, JCG (GNU Compiler for Java) Excelsior JET ( ) -JRE.

- , . , Linux.

, , script. , Linux script.

script. . $1 fyi.

#!/bin/sh
java Main $1

, script "" , main test.txt, .

Windows, Windows "java Main test.text", ( ). , , , .

+1

Mac .bash_profile

alias main='java main'

, ,

+1

. , Linux bash alias, main java -cp myjar.jar main.

Linux , "" Java- , . ( Linux).

If you are in the windows, you will have to wait for an answer from someone who has more knowledge about this than me.

Good luck

0
source

All Articles