1

I've just downloaded swagger-codegen-cli (doesn't matter what it is, it's just an executable jar) in a Windows 10 OS, which runs from the command line. So to execute it I must go to the corresponding folder (in the command prompt, of course), and there run:

jara -jar swagger-codegen-cli-2.2.2.jar <command> [<args>]

which is, as you may see, quite annoying. I know I can create a batch file (.cmd extension) and add the path to that file in the PATHenvironment variable but I'm not sure how to write that batch. Can anyone say how to write that batch so I can write something like swagger-codegen <command> [<args>] from anywhere in the command line?

It would be like an alias which I can add to PATH, do I make myself clear? Thanks in advance for your answers.

  • where ever the executable is just put it in quotes "C:\temp\crap\myexecutable.exe" so I guess it would look something like this in your batch file. Also batch file would be .bat extension. jara -jar "C:\temp\swagger-codegen-cli-2.2.2.jar" <command> [<args>] – LSxCPU May 5 '17 at 13:47
  • Hi, we're not a script writing service. Write your batch, and put it in a path that's in your PATH environment variable. Where are you getting stuck exactly? And what have you tried so far to get un-stuck? – Ƭᴇcʜιᴇ007 May 5 '17 at 13:48
  • @Ƭᴇcʜιᴇ007 that's the thing, I don't know how to write a batch file, so I ask for help. I assume it's a simple task and it isn't something I need to do every day, so it's not practical for me to dive into some batch documentation and/or tutorial. I was reading the Maven batch (it's at hand for me) and was quite complex, so I didn't know how to deal with the matter. BTY, I think the accepted answer is useful information for a newbie in this matter like me. Sorry if I made you lose your time, you don't have to pay attention to my questions if you think it's not worth it. Best regards. – Alvaro Pedraza May 5 '17 at 19:08
3

If your jar is at C:\Program Files\Java\swagger-codegen-cli-2.2.2.jar, then your swagger-codegen.bat should contain:

@echo off

java -jar "C:\Program Files\Java\swagger-codegen-cli-2.2.2.jar" %*

The @echo off is explained in this Stack Overflow answer, and the %* represents the arguments passed to the batch file (explained in this answer).

0

Another way is to create your bat file s-codegen.bat (for example). Then add these lines...

@echo off    
cd /d "C:\Program Files\Java\swagger-codege\"
java -jar swagger-codegen-cli-2.2.2.jar args

You may modify path according to the location where jar file is present.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.