Browse Source

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
master
Stephane Bailliez 23 years ago
parent
commit
d957fa1151
2 changed files with 25 additions and 5 deletions
  1. +11
    -5
      src/main/org/apache/tools/ant/types/CommandlineJava.java
  2. +14
    -0
      src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java

+ 11
- 5
src/main/org/apache/tools/ant/types/CommandlineJava.java View File

@@ -69,7 +69,7 @@ import org.apache.tools.ant.taskdefs.condition.Os;
* a java command line. * a java command line.
* *
* @author thomas.haas@softwired-inc.com * @author thomas.haas@softwired-inc.com
* @author <a href="sbailliez@apache.org">Stephane Bailliez</a>
* @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
*/ */
public class CommandlineJava implements Cloneable { public class CommandlineJava implements Cloneable {


@@ -234,10 +234,6 @@ public class CommandlineJava implements Cloneable {
// first argument is the java.exe path... // first argument is the java.exe path...
result[pos++] = vmArgs[0]; result[pos++] = vmArgs[0];
// -jar must be the first option in the command line.
if (executeJar){
result[pos++] = "-jar";
}
// next follows the vm options // next follows the vm options
System.arraycopy(vmArgs, 1, result, pos, vmArgs.length - 1); System.arraycopy(vmArgs, 1, result, pos, vmArgs.length - 1);
pos += vmArgs.length - 1; pos += vmArgs.length - 1;
@@ -253,10 +249,20 @@ public class CommandlineJava implements Cloneable {
result[pos++] = "-classpath"; result[pos++] = "-classpath";
result[pos++] = fullClasspath.toString(); 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. // this is the classname to run as well as its arguments.
// in case of 'executeJar', the executable is a jar file. // in case of 'executeJar', the executable is a jar file.
System.arraycopy(javaCommand.getCommandline(), 0, System.arraycopy(javaCommand.getCommandline(), 0,
result, pos, javaCommand.size()); result, pos, javaCommand.size());

return result; return result;
} }




+ 14
- 0
src/testcases/org/apache/tools/ant/types/CommandlineJavaTest.java View File

@@ -120,4 +120,18 @@ public class CommandlineJavaTest extends TestCase {
"org.apache.tools.ant.CommandlineJavaTest", s[5]); "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]);
}

} }

Loading…
Cancel
Save