batch file to run jar file with parameters

后端 未结 4 1959
南旧
南旧 2021-01-04 22:51

How can I run a batch file and pass parameters to jar file?

this doesn\'t work

mybat.bat

java -jar log_parser.jar %1 %2 %3 %         


        
相关标签:
4条回答
  • 2021-01-04 23:18

    I just tried with a small java program that only dumps the arguments to the screen:

    public static void main(String[] args)
    {
        for(String s : args)
        {
            System.out.println(s);
        }
    }   
    

    and the following batch file :

    java -jar test.jar %1 %2 %3 %4
    

    and I ended up with the following result

    -file
    C:\\trace_small.log
    -str
    Storing
    

    For the same command line as you... the equal sign '=' desapeared. Now if you trun the batch file to this :

    java -jar test.jar %*
    

    you will get yet another result (which might be what you expected - not clear)

    -file=C:\\trace_small.log
    -str=Storing
    

    The advantage on this %* syntax, is that it is more extensible by accepting any number of arguments.

    Hope this helps, but I recommend you to have a look at your code to and add some debug statement to understand where you are "lossing" some part of the input.

    0 讨论(0)
  • 2021-01-04 23:19

    For Example Opening Street Map Editor in Windows 10 x64

    > cd "C:\Program Files\Java\jre1.8.0_161\bin\"
    
    > javaw.exe -Xmx2048m -jar "C:\Program Files (x86)\JOSM\josm-tested.jar"
    
    0 讨论(0)
  • 2021-01-04 23:35

    In my case I use the following bat-file:

    @echo off
    PATH_TO_JRE\bin\java.exe -jar -Denable=true your_file.jar
    

    At this particular case then in java code I can get the param "enable" like this:

    Boolean.getBoolean("enable") 
    
    0 讨论(0)
  • 2021-01-04 23:40

    1) You could try to use

    "-Dfile=C:\trace_small.log -Dstr=Storing"

    The variables would be set as Java System Property, but not as Parameters into a main-method.

    2) Try to put the arguments without '='

    log_parser.bat -file C:\trace_small.log -str Storing

    0 讨论(0)
提交回复
热议问题