0

I have a need to pass multiple command line parameters to the executable jar. I am trying to automate one of the manual task. I am trying to read from one file and writing it's content to other files based on command line argument.

Here is the command :

> java -jar CreateFiles.jar  C:\source\MasterFile.xlsx C:\destination\Dump_here\ 2 100


arg[0]: master file
arg[1]: Destination Directory and this is not a file. Here files will be generated with some suffix like File_1,File_2 etc.
arg[2]: number of files
arg[3]: records in each file

Things I tried: -While first argument arg[0] seems fine, its failing at arg[1]. -once I removed arg[1], just to check whether it gets through, it fails at arg[2] which is an integer value.

How can I achieve the purpose here ?

Main method:

    String RawFile = args[0];
    String DestinationPath=args[1];
    int numFiles = Integer.parseInt(args[2]);
    int numRecords = Integer.parseInt(args[3]);

I am getting below error :

> Analysing C:\source\MasterFile.xlsx Exception in thread "main"
> org.apache.commons.compress.archivers.ArchiveException: Archiver:
> C:\destination\Dump_here\ not found.  at
> org.apache.commons.compress.archivers.ArchiveStreamFactory.createArchiveInputStream(ArchiveStreamFactory.java:391)
>   at
> org.apache.commons.compress.archivers.ArchiveStreamFactory.createArchiveInputStream(ArchiveStreamFactory.java:328)
>   at
> org.apache.commons.compress.archivers.Lister.createArchiveInputStream(Lister.java:71)
>   at
> org.apache.commons.compress.archivers.Lister.listStream(Lister.java:59)
>   at org.apache.commons.compress.archivers.Lister.main(Lister.java:53)
Abhay Singh
  • 171
  • 1
  • 7
  • 1
    The issue seems to be with what you pass to the method in apache Compress library, have you checked the documentation? Maybe you could share that code? – Joakim Danielson Mar 29 '19 at 12:32
  • Possible duplicate of [How do I pass parameters to a jar file at the time of execution?](https://stackoverflow.com/questions/456636/how-do-i-pass-parameters-to-a-jar-file-at-the-time-of-execution) – Ramesh Subramanian Mar 29 '19 at 12:33
  • 1
    Seems to work just fine then, the class seems to be complaining about the specified directory not existing. – Gimby Mar 29 '19 at 12:34
  • The problem is that all the arguments I am sending, its expecting to be a file path. Why can't its taking it as a normal string and integers. – Abhay Singh Mar 30 '19 at 16:22
  • I did a bit of debugging and found that the issue was with project structure in intellij. Moved the Meta-INF folder under resources and took the build again. It worked after the change. Thanks. – Abhay Singh Apr 01 '19 at 08:11

0 Answers0