Return-Path: Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 46047 invoked by uid 500); 2 Aug 2003 16:14:53 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 90092 invoked from network); 2 Aug 2003 11:38:07 -0000 From: "Iwan" To: "'Ant Users List'" Subject: RE: Starting jboss with Ant (again !!! - and still no luck :( ) Date: Sat, 2 Aug 2003 13:37:41 +0200 Message-ID: <007101c358ea$7f3b7360$0c02a8c0@LAPTOP01> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 In-Reply-To: <009901c357fb$c9df0570$020200c0@DJ0X820J> Importance: Normal X-Loop-Detect: 1 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N This works perfectly for me on Windows... Here's how I did it using the spawn-task that was posted recently. Below = you also find a post of Tim Gordon, who recently posted a spawn-task on this mailinglist. +-----------------------------+ | | | S T A R T I N G J B O S S | | | +-----------------------------+ This will take some time, possibly up to a minute. +-----------------------------+ | J B O S S S T A R T E D | +-----------------------------+ =20 JBoss is already running on ${jboss.host}:${jboss.port} - [${jboss_already_running}] =20 +-----------------------------+ | | | S T O P P I N G J B O S S | | | +-----------------------------+ +-----------------------------+ | J B O S S S T O P P E D | +-----------------------------+ +--------------------------+ | J B O S S F A I L E D | +--------------------------+ -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D = TIM's POST START -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D Lots of people seem to ask how to spawn a process that will live beyond = ANT. There are other ways, but this works for me... Don't rely on any console I/O, though - it's not piped in and whatever's piped out will cease to = do so once the ANT JVM exits. Generally intended for things that write logs, = have gui's, start their own shells, etc. Ruthlessly hacked from ExecTask, so it's a bit untidy. Works, though. eg: Usual path considerations apply. ---------------------- import java.io.File; import java.io.FileOutputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.BufferedReader; import java.io.StringReader; import org.apache.tools.ant.Task; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.util.StringUtils; import org.apache.tools.ant.taskdefs.Execute; import org.apache.tools.ant.taskdefs.LogStreamHandler; import org.apache.tools.ant.types.Environment; import org.apache.tools.ant.types.Commandline; /** * Spawns an asynchronous process from ANT * * @author Tim Gordon */ public class Spawn extends Task { private String os; private File out; private File dir; protected boolean newEnvironment =3D false; private Environment env =3D new Environment(); protected Commandline cmdl =3D new Commandline(); private FileOutputStream fos =3D null; private ByteArrayOutputStream baos =3D null; private String outputprop; private boolean failIfExecFails =3D true; private boolean append =3D false; /** * Controls whether the VM (1.3 and above) is used to execute the * command */ private boolean vmLauncher =3D true; /** * The command to execute. */ public void setExecutable(String value) { cmdl.setExecutable(value); } /** * The working directory of the process. */ public void setDir(File d) { this.dir =3D d; } /** * List of operating systems on which the command may be executed. */ public void setOs(String os) { this.os =3D os; } /** * @ant.attribute ignore=3D"true" */ public void setCommand(Commandline cmdl) { log("The command attribute is deprecated. " + "Please use the executable attribute and nested arg elements.", Project.MSG_WARN); this.cmdl =3D cmdl; } /** * File the output of the process is redirected to. */ public void setOutput(File out) { this.out =3D out; } /** * Property name whose value should be set to the output of * the process. */ public void setOutputproperty(String outputprop) { this.outputprop =3D outputprop; } /** * Do not propagate old environment when new environment variables are specified. */ public void setNewenvironment(boolean newenv) { newEnvironment =3D newenv; } /** * Add an environment variable to the launched process. */ public void addEnv(Environment.Variable var) { env.addVariable(var); } /** * Adds a command-line argument. */ public Commandline.Argument createArg() { return cmdl.createArgument(); } /** * Stop the build if program cannot be started. Defaults to true. * * @since Ant 1.5 */ public void setFailIfExecutionFails(boolean flag) { failIfExecFails =3D flag; } /** * Whether output should be appended to or overwrite an existing file. * Defaults to false. * * @since 1.30, Ant 1.5 */ public void setAppend(boolean append) { this.append =3D append; } /** * Do the work. */ public void execute() throws BuildException { File savedDir =3D dir; // possibly altered in prepareExec checkConfiguration(); if (isValidOs()) { try { runExec(prepareExec()); } finally { dir =3D savedDir; } } } /** * Has the user set all necessary attributes? */ protected void checkConfiguration() throws BuildException { if (cmdl.getExecutable() =3D=3D null) { throw new BuildException("no executable specified", location); } if (dir !=3D null && !dir.exists()) { throw new BuildException("The directory you specified does not " + "exist"); } if (dir !=3D null && !dir.isDirectory()) { throw new BuildException("The directory you specified is not a " + "directory"); } } /** * Is this the OS the user wanted? */ protected boolean isValidOs() { // test if os match String myos =3D System.getProperty("os.name"); log("Current OS is " + myos, Project.MSG_VERBOSE); if ((os !=3D null) && (os.indexOf(myos) < 0)) { // this command will be executed only on the specified OS log("This OS, " + myos + " was not found in the specified list of valid OSes: " + os, Project.MSG_VERBOSE); return false; } return true; } /** * If true, launch new process with VM, otherwise use the OS's shell. */ public void setVMLauncher(boolean vmLauncher) { this.vmLauncher =3D vmLauncher; } /** * Create an Execute instance with the correct working directory set. */ protected Execute prepareExec() throws BuildException { // default directory to the project's base directory if (dir =3D=3D null) { dir =3D project.getBaseDir(); } Execute exe =3D new Execute( new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN) { public void stop() { // Just let the daemon threads handle output for the lifetime = of this ANT invocation... } } ) { protected void waitFor(Process process) { // Don't want to wait for a detached process... } }; exe.setAntRun(getProject()); exe.setWorkingDirectory(dir); exe.setVMLauncher(vmLauncher); String[] environment =3D env.getVariables(); if (environment !=3D null) { for (int i =3D 0; i < environment.length; i++) { log("Setting environment variable: " + environment[i], Project.MSG_VERBOSE); } } exe.setNewenvironment(newEnvironment); exe.setEnvironment(environment); return exe; } /** * A Utility method for this classes and subclasses to run an * Execute instance (an external command). */ protected final void runExecute(Execute exe) throws IOException { exe.execute(); if (baos !=3D null) { BufferedReader in =3D new BufferedReader(new StringReader(Execute.toString(baos))); String line =3D null; StringBuffer val =3D new StringBuffer(); while ((line =3D in.readLine()) !=3D null) { if (val.length() !=3D 0) { val.append(StringUtils.LINE_SEP); } val.append(line); } project.setNewProperty(outputprop, val.toString()); } } /** * Run the command using the given Execute instance. This may be * overidden by subclasses */ protected void runExec(Execute exe) throws BuildException { // show the command log(cmdl.describeCommand(), Project.MSG_VERBOSE); exe.setCommandline(cmdl.getCommandline()); try { runExecute(exe); } catch (IOException e) { if (failIfExecFails) { throw new BuildException("Execute failed: " + e.toString(), e, location); } else { log("Execute failed: " + e.toString(), Project.MSG_ERR); } } finally { // close the output file if required logFlush(); } } /** * Flush the output stream - if there is one. */ protected void logFlush() { try { if (fos !=3D null) { fos.close(); } if (baos !=3D null) { baos.close(); } } catch (IOException io) { } } } ----------------- Tim Gordon Allustra Limited 1 Royal Exchange Avenue London EC3V 3LT Tel 020 7464 4190 Tel 020 7464 4194 http://www.allustra.com/ -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D = TIM's POST END -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D Iwan > -----Original Message----- > From: Antoine Levy-Lambert [mailto:antoine@antbuild.com]=20 > Sent: Friday, August 01, 2003 9:09 AM > To: Ant Users List > Subject: Re: Starting jboss with Ant (again !!! - and still=20 > no luck :( ) >=20 >=20 > Also, I think you need a /C flag or something like that with=20 > cmd to start an application server. >=20 > so you would have >=20 > > > > >=20 > (check the exact flag for cmd.exe, have a look at cmd /? )=20 > Cheers, Antoine > ----- Original Message ----- > From: "Antoine Levy-Lambert" > To: "Ant Users List" > Sent: Friday, August 01, 2003 8:58 AM > Subject: Re: Starting jboss with Ant (again !!! - and still=20 > no luck :( ) >=20 >=20 > > Hi Giles, > > > > the executable should be "cmd.exe", not "${bin}run.bat" > > > > the same on SunOS, the executable should be "sh" or "ksh",=20 > but not the > name > > of the script > > > > other point : there is a spawn attribute for the exec task in=20 > > ant1.6alpha, you can try it. > > > > Cheers, > > > > Antoine > > ----- Original Message ----- > > From: "Parnell, Giles (AU - Sydney)" > > To: > > Sent: Friday, August 01, 2003 6:33 AM > > Subject: Starting jboss with Ant (again !!! - and still no luck :( ) > > > > > > > Sorry guys > > > > > > I know this topic has been fired around quite a bit lately. I've > followed > > > all the responses but still to be doing something wrong. > > > > > > I've compiled the Spawn class (many thanks to T Gordon) into it's=20 > > > own > jar, > > > and included it in the ant lib dir. > > > > > > I've included the taskdef in my build script, and it=20 > appears to work > fine > > > (my build script acknowledges the new task) > > > > > > However when I run the portion of xml to start jboss, I get the > following > > > error: > > > > > > [spawn] BUILD FAILED:=20 > > > file:Z:/workspace/MinterEllison/src/build.xml:149: > > > Execute failed: java.io.IOException: CreateProcess: > > >=20 > c:APPSERVERS\jboss-3.0.7_jakarta-tomcat-4.1.24\bin\run.bat -c=20 > connectis > > > error=3D3 > > > [if] Error in class net.sf.antcontrib.logic.IfTask > > > > > > I know it's got nothing to do with the 'if task' (part of=20 > > > ant-contrib), > > and > > > take it that the error=3D3 is the thing that's causing the problem > > > > > > Heres my target... any ideas ? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > bin is decalred as so above... > > > > > = value=3D"${appserverroot}/jboss-3.0.7_jakarta-tomcat-4.1.24/bin/"/> > > > > > > > > > Thanks in advance > > > Giles > > > > > > "...the opportunities that are proffered by corporate=20 > websites, web=20 > > > advertising and email are too great to ignore", according to the > > Australian > > > Financial Review's 2003 Marketing Survey. > > > > > > Eclipse can help you use new media to engage your=20 > customers. To find=20 > > > out how, please contact Jamie Verco on 9322 5181 or 0408 202 203. > > > > > > > > > Giles Parnell | ECLIPSEGROUP | 02 9322 5124 | =20 > Mobile 0403 > > 768656 > > > > > > Level 9, 190 George Street, Sydney, NSW 2000, Fax: 02 9322 5121 > > > > > > > The Eclipse Group is a wholly owned subsidiary of=20 > Deloitte Touche > > Tohmatsu > > > > > > > www.eclipsegroup.com.au > > > > > > This email and any files transmitted with it are confidential and > intended > > > solely > > > for the use of the individual or entity to whom they are=20 > addressed.=20 > > > If you are not the intended recipient of this email, you must not=20 > > > disseminate, copy or otherwise use this information. If you have=20 > > > received this email > in > > > error, > > > please notify Eclipse Group immediately. > > > > > > > > > > > > > > > > > > > > > > > > ***********Confidentiality/Limited Liability=20 > > > Statement*************** > > > > > > This message contains privileged and confidential information=20 > > > intended only for the use of the addressee named above. =20 > If you are=20 > > > not the intended recipient of this message, you must not=20 > > > disseminate, copy or take any action in reliance on it. =20 > If you have=20 > > > received this message in error, please notify Deloitte Touche=20 > > > Tohmatsu immediately. Any views expressed in this=20 > message are those=20 > > > of the individual sender, except where the sender specifically=20 > > > states them to be the views of Deloitte. > > > > > > The liability of Deloitte Touche Tohmatsu, is limited by,=20 > and to the=20 > > > extent of, the Accountants' Scheme under the Professional=20 > Standards=20 > > > Act 1994 (NSW). > > > > > > The sender cannot guarantee that this email or any=20 > attachment to it=20 > > > is free of computer viruses or other conditions which may=20 > damage or=20 > > > interfere with data, hardware or software with which it might be=20 > > > used. It is sent on the strict condition that the user=20 > carries out=20 > > > and relies on its own procedures for ensuring that its=20 > use will not=20 > > > interfere with the recipients systems and the recipient=20 > assumes all=20 > > > risk of use and absolves the sender of all responsibility for any=20 > > > consequence of its > use. > > > > > > > > > > > > > >=20 > --------------------------------------------------------------------- > > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org > > For additional commands, e-mail: user-help@ant.apache.org > > > > >=20 >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org > For additional commands, e-mail: user-help@ant.apache.org >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org