Setting a filecollection that includes spaces as a classpath for JavaExec fails

(Joshua Street) #1

I am trying to pass the compile configuration file collection as the classpath to a javaexec task that I have running. I have spaces in the file paths of some of the directories. I keep seeing failures when trying to execute my java executable because it cannot find class ‘Files’. This is 100% because there are no quotes around my classpath.

I ultimately have a command similar to: java -cp C:\Program Files (x86)\foo.jar You can see that the java command is interpreting Files as my class because there are no quotes around the classpath argument.

I am on windows, developing a plugin in Java. I set my classpath by using the JavaExecSpec.setClassPath(FileCollection) method. Is this a bug? I can’t seem to find a way to make sure the classpath is properly set for the command.

(Joshua Street) #2

Here is a small example of what I am trying to do and how it shows up after calling spec.getCommandLine():


“c:/program files (x86)/ibm/sdp75/runtimes/base_v61/deploytool/itp/batch2.jar”,
“c:/program files (x86)/ibm/sdp75/runtimes/base_v61/deploytool/itp/batch2_n11.jar”)


c:\program files (x86)\ibm\sdp75\runtimes\base_v61\java\bin\java.exe
c:\program files (x86)\ibm\sdp75\runtimes\base_v61\deploytool\itp\batch2.jar;c:\program files (x86)\ibm\sdp75\runtimes\base_v61\deploytool\itp\batch2_n11.jar

You can see how the classpath contains spaces that are not enclosed in quotes.