• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Running a jar file from a DOS batch file.

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given the batch file contents below, is it possible to execute a batch file that runs a jar file with upto 5 arguments? The batch commands below gives me a DOS error "mycode is not recognized as an internal or external command, operable program or batch file".
>
>
> @echo off
>
> C:\mycode\java -jar mycode.jar %1 %2 %3 %4 %5
>
>
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must have some kind of syntax error in the batch file. The system is looking only at C:\mycode and presumably only finding a directory there. It's been a while since DOS 6.2 but I think the only limitation to a command line is 1024 chars total. The number of args is irrellavent.
 
Sonny Pondrom
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Micheal,
Can you think of a test case that should work on any system?
like some util or system jar file that would have an argument.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sonny Pondrom:
Thanks Micheal,
Can you think of a test case that should work on any system?
like some util or system jar file that would have an argument.


Write a simple Java app that takes a command line argument, jar it up and test it.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Backing up a bit:
Try
java -version
or
C:\mycode\java -version

Then compile something like

and try
C:\mycode\java Hello
This tests some of the more fundamental stuff before you worry about the -jar and command line arguments.
Also, I'd recommend setting echo on rather than off, for debugging at least. Find out what those %1 %2 %3 %4 %5 really evaluate to.
Good luck.
[ July 26, 2003: Message edited by: Jim Yingst ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also try this free software at http://www.GreenTeaTech.com that allows you to run any exe or jar files locally or on remote machines.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sonny Pondrom:
Given the batch file contents below, is it possible to execute a batch file that runs a jar file with upto 5 arguments? The batch commands below gives me a DOS error "mycode is not recognized as an internal or external command, operable program or batch file".
>
>
> @echo off
>
> C:\mycode\java -jar mycode.jar %1 %2 %3 %4 %5
>
>


Are you sure, that java is located in C:\mycode???
I would think you need something like this:
C:
cd C:\mycode
C:\Programms\jdk7.4.4\bin\java -jar mycode.jar %1 %2 ....
Of course the jarfile must be made with Main-Class and so on.
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The proble is not with parameters or with the jar File.
"C:\mycode\java -jar mycode.jar %1 %2 %3 %4 %5" - the operating system is expecting "Java.xxx" in "C:\mycode\" Folder.
Rather you should use
CD C:\mycode\
Java ....
(Asuming Java is in Path)
 
Sonny Pondrom
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All suggestions were helpful. But the last two were the best.
I ended up doing something like this:
@echo off
REM save current directory
PUSHD C:\java\classes\my_code
java -jar My_code.jar %1 %2 %3 %4 %5 %6 %7 %8
REM restores previous directory
POPD
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sonny Pondrom:
All suggestions were helpful. But the last two were the best.
...


So I hope this will take away this smelling 'greenhorn' label from me .
[ August 05, 2003: Message edited by: Stefan Wagner ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic