From d957fa1151163d513197a174a098e2aac8745b1e Mon Sep 17 00:00:00 2001 From: Stephane Bailliez Date: Sat, 2 Feb 2002 12:29:24 +0000 Subject: [PATCH] Fix -jar option to be appended rather than prepended as specified in usage command line since the parsing for jvmtype is broken in JDK < 1.4.0. I filled bugs 139128 and 139129 to Sun for this. Reported by: christophe.aubry@temis-group.com (Christophe Aubry) PR: 5307 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271071 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/types/CommandlineJava.java | 16 +++++++++++----- .../tools/ant/types/CommandlineJavaTest.java | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) 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]); + } + }