From 458b181fc1b9e747bf0569c91372dd89f67559cb Mon Sep 17 00:00:00 2001 From: Stephane Bailliez Date: Thu, 2 Aug 2001 21:52:59 +0000 Subject: [PATCH] Added the support to the -jar option in the command line per suggestion of git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269445 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Java.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Java.java b/src/main/org/apache/tools/ant/taskdefs/Java.java index ceaa8614b..fab7af7b7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Java.java +++ b/src/main/org/apache/tools/ant/taskdefs/Java.java @@ -102,10 +102,12 @@ public class Java extends Task { */ public int executeJava() throws BuildException { String classname = cmdl.getClassname(); - - if (classname == null) { + if (classname == null && cmdl.getJar() == null) { throw new BuildException("Classname must not be null."); } + if (!fork && cmdl.getJar() != null){ + throw new BuildException("Cannot execute a jar in non-forked mode. Please set fork='true'. "); + } if (fork) { log("Forking " + cmdl.toString(), Project.MSG_VERBOSE); @@ -152,10 +154,23 @@ public class Java extends Task { createClasspath().setRefid(r); } + /** + * set the jar name... + */ + public void setJar(File jarfile) throws BuildException { + if ( cmdl.getClassname() != null ){ + throw new BuildException("Cannot use 'jar' and 'classname' attributes in same command."); + } + cmdl.setJar(jarfile.getAbsolutePath()); + } + /** * Set the class name. */ - public void setClassname(String s) { + public void setClassname(String s) throws BuildException { + if ( cmdl.getJar() != null ){ + throw new BuildException("Cannot use 'jar' and 'classname' attributes in same command"); + } cmdl.setClassname(s); }