0

I'm building a desktop app on Java (11) and compiled with Maven, but I need to send a Filepath as an argument to read it:

public class App {
public static void main(String[] args) {
    if (args.length == 0) {
        System.out.println("File name not specified.");
        System.exit(1);
    }
    System.out.println(args[0]);

    readFile(args[0]);
}
}

I don't know how to run the app sending that parameter or which command is needed in the Command Line

Wion
  • 13
  • 4
  • How have you compiled with Maven? Do you have an executable jar file? Next, what platform are you using? Finally, what filepath do you want to send? Assuming it's a `jar` and you're on Windows, `java -jar my.jar "C:/Some File/Path.txt"` – Elliott Frisch Sep 28 '22 at 21:29
  • https://stackoverflow.com/questions/10108374/maven-how-to-run-a-java-file-from-command-line-passing-arguments – g00se Sep 28 '22 at 21:45
  • It worked, thank you, sorry I didn't know I need a Jar, about the questions, yes I tried with Maven but in my ignorance, maybe I did it wrong, also, yes, I'm on Windows and the filepath could be any since will be a User input, but it worked having the Jar, thanks! – Wion Sep 28 '22 at 21:45

0 Answers0