Skip to content
Advertisement

How to pass system variable with normal variable to call java program in command line batch script

java -cp %EPM_JAVA_CLASSPATH% -DEPM_ORACLE_INSTANCE=%1 -DHFM_CLUSTER=%2 -DHFM_APPLICATION=%3 runConsoltesting %4 %5 %6 %7

When i try to access 5th argument it shows:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at runConsoltesting.main(runConsoltesting.java:42)

It takes only arguments upto class name

Advertisement

Answer

Whatever given after main class runConsoltesting are main method arguments which are totally 4 (%4,%5,%6,%7). So you are getting ArrayOutOfBoundException when you try to access fifth element.

%1, %2 and %3 are JVM arguments and NOT java main method arguments. So these can be read in code as below.

System.getProperty(String property), here property is name of your -D argument.

For example, System.getProperty(“EPM_ORACLE_INSTANCE”) will return the value which is set for place of %1.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement