简体   繁体   中英

Using shell script to pass args to Java

I have a Java project with gradle. This project has a main method.

I know I can run the main method using ./gradlew run but I cannot pass args to the Java main method using this function

I want to create a single-word bash script like ./runMyCode that can accept args such as ./runMyCode hello.txt -f which will be eventually be passed to the java application.

However I am unable to do this. PLease help me...

You could build an executable jar with gradle . Then your runMyCode script would look like this:

#!/bin/bash

java -jar my-code.jar "$@"

And you can use as you wished: ./runMyCode hello.txt -f .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM