diff --git a/src/main/org/apache/tools/ant/types/CommandlineJava.java b/src/main/org/apache/tools/ant/types/CommandlineJava.java index f05acd449..9034778d2 100644 --- a/src/main/org/apache/tools/ant/types/CommandlineJava.java +++ b/src/main/org/apache/tools/ant/types/CommandlineJava.java @@ -69,7 +69,7 @@ import org.apache.tools.ant.taskdefs.condition.Os; * a java command line. * * @author thomas.haas@softwired-inc.com - * @author Stephane Bailliez + * @author Stephane Bailliez */ public class CommandlineJava implements Cloneable { @@ -234,10 +234,6 @@ public class CommandlineJava implements Cloneable { // first argument is the java.exe path... result[pos++] = vmArgs[0]; - // -jar must be the first option in the command line. - if (executeJar){ - result[pos++] = "-jar"; - } // next follows the vm options System.arraycopy(vmArgs, 1, result, pos, vmArgs.length - 1); pos += vmArgs.length - 1; @@ -253,10 +249,20 @@ public class CommandlineJava implements Cloneable { result[pos++] = "-classpath"; result[pos++] = fullClasspath.toString(); } + + // JDK usage command line says that -jar must be the first option, as there is + // a bug in JDK < 1.4 that forces the jvm type to be specified as the first + // option, it is appended here as specified in the docs even though there is + // in fact no order. + if (executeJar){ + result[pos++] = "-jar"; + } + // this is the classname to run as well as its arguments. // in case of 'executeJar', the executable is a jar file. System.arraycopy(javaCommand.getCommandline(), 0, result, pos, javaCommand.size()); + return result; } diff --git a/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java b/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java index 786fe8525..fa97309b6 100644 --- a/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java +++ b/src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java @@ -120,4 +120,18 @@ public class CommandlineJavaTest extends TestCase { "org.apache.tools.ant.CommandlineJavaTest", s[5]); } + public void testJarOption() throws Exception { + CommandlineJava c = new CommandlineJava(); + c.createArgument().setValue("arg1"); + c.setJar("myfile.jar"); + c.createVmArgument().setValue("-classic"); + c.createVmArgument().setValue("-Dx=y"); + String[] s = c.getCommandline(); + assertEquals("-classic", s[1]); + assertEquals("-Dx=y", s[2]); + assertEquals("-jar", s[3]); + assertEquals("myfile.jar", s[4]); + assertEquals("arg1", s[5]); + } + }