How do I stop Java program arguments being mistaken for VM arguments?

batch-file, java

Solution

I think your issue has more to do with passing in variables. Remove EnableDelayedExpansion EnableExtensions

Problem

Inside a bat file I have the following: `java -Ddatabase.host=127.0.0.1 -Xms128M -Xmx1024M com.temp.util.manual.serial.Assignment -folder C:\temp\ -destination C:\temp\out.csv` The `-folder` and `-destination` params are supposed to be passed to the main method of the Assignment class being called, but instead they are being interpreted as VM Args. I tried putting quotes around the params to no avail, and searching does not reveal an answer. I get the following error: ``` Unrecognized option: -'destination' Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. Press any key to continue . . . @echo off setlocal EnableDelayedExpansion EnableExtensions set FILETYPE=%~n0 set CLASSPATH=jar1.jar set CLASSPATH=%CLASSPATH%;anotherjar.jar echo %CLASSPATH% java -DjobName=%FILETYPE% -Ddatabase.host=127.0.0.1 -Ddatabase.name=db1 -Ddatabase.username=user1 -Ddatabase.password=password1 -Xms128M -Xmx1024M com.temp.util.manual.serial.Assignment -folder C:\\temp\\ -destination C:\\temp\\out.csv call Cleanup.bat endlocal ```

Original source