JJ Nooby
JJ Nooby

Reputation: 1

Java Filepath Question

I am trying to finish a java program that uploads a file from a client machine to a webserver. The java program is executed with a bat script. I need to pass in a file name to the java program somehow since the filename is different every time. Or can i somehow use %1 instead of the filepath? I dont know.

Upvotes: 0

Views: 285

Answers (3)

JJ Nooby
JJ Nooby

Reputation: 1

No they got it, if i could just pass the filepath as a parameter to the executed jar that would be awesome. Just need to figure out how to pass that parameter into a variable in the program....

Upvotes: 0

Jesper
Jesper

Reputation: 207006

What does the batch file look like that runs the Java program? You can indeed use parameters like this:

java -jar program.jar %1

If you put that line in a file runprogram.bat, then you could run it with:

runprogram somefilename.xyz

and somefilename.xyz will be passed to the Java program as a command line argument.

Upvotes: 1

Bozhidar Batsov
Bozhidar Batsov

Reputation: 56665

Why not simply forward the parameters passed to the shell script to the Java application. I usually do something like this:

#!/bin/zsh

java -jar someapp.jar $@

This will pass all the arguments with which the script was executed to the java app and you can act upon them - as far as I understand you need only only - the file path. I'm not familiar with bat scripts, but I assume they have some similar way of passing args around.

Upvotes: 1

Related Questions