0

I'm trying to write a batch file (run.bat) that can be invoked something like this:

run.bat "whatever.log"

But under the hood, the batch file is passing the argument ("whatever.log") to the following command:

java -cp "fizz.jar;a.jar;b.jar;c.jar;d.jar" com.myapp.FizzDriver "whatever.log"

Again, if you run: run.bat "blah.txt", then that batch file would execute:

java -cp "fizz.jar;a.jar;b.jar;c.jar;d.jar" com.myapp.FizzDriver "blah.txt"

My best attempt at run.bat so far is:

@ECHO OFF
%JAVA_HOME%\bin\java java -cp "fizz.jar;a.jar;b.jar;c.jar;d.jar" com.myapp.FizzDriver ???

But I'm not sure how to parameterize the argument (???). I'm also not sure if the batch file is missing anything or is incorrect with the way I've written it. Ideas? Thanks in advance!

0

2 Answers 2

2

You just need to put %1, but you have another issue. When you use 'java -jar', the '-cp' argument is ignored: the CLASSPATH is taken from the jar manifest only.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @EJP - what if I made my Java command-line: java -cp "fizz.jar;a.jar;b.jar;c.jar;d.jar" com.myapp.FizzDriver %1? (Where FizzDriver is the main class inside fizz.jar). Would that fix the batch file? Thanks again!
That would fix the classpath problem, but it's a retrograde step. You should specify both the Class-path and the Main-class in the JAR manifest. Complete encapsulation that way. All the batch file should do is run the JAR file and pass the argument()s. If you can have more than one argument, specify %1 %2 %3 %4 %5 %6 %7 %8 %9.
2

To pass one command line parameter, use %1. If you need to pass more than one, you can either use %1 %2 etc, or use %* to pass all of them at once.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.