Start Jboss with Ant. Command exec doesn't work - ant

I try to start JBoss with ant.
When i execute this script :
<target name="start-jboss" >
<exec executable="${jboss.bin.dir}\run.bat" >
<arg line="--configuration=Myserver -b localhost" />
</exec>
</target>
JBoss is blocking at this step :
[exec] 15:52:55,373 INFO [AjpProtocol] Initializing Coyote AJP/1.3 on ajp-localhost%2F127.0.0.1-8009
But when i run the run.bat it works... Its the same when i add spawn="true" in exec.
I think that the problem comes from eclipse...
Thanks

To run a batchfile use cmd as executable, something like :
<exec dir"yourworkingdir" executable="cmd" failonerror="true">
<arg line="/c ${jboss.bin.dir}\run.bat --configuration=Myserver -b localhost"/>
</exec>
if arg line=... doesn't work, use arg value=... for every parameter.
EDIT : if you have trouble using the batchfile, why not get rid of using that addtional batchfile and use the java task straightforward as explained here ?

Related

Jenkins cannot execute webpack from ant script

I am trying to execute an Ant script through jenkins but it fails when it attempts to use webpack...
The ant script's execution task is the following:
<exec executable="webpack.cmd" failonerror="true">
<env key="PROD_ENV" value="true"/>
</exec>
where webpack.cmd has been installed as a global npm module. The module directory has been included in the Path variable and I have even made sure that Jenkins is actually able to see it by doing a trial run inside a Execute windows batch command build step. However when it attempts to execute it via Ant it fails. Could it be a problem with the Ant plugin and its version?
The error i'm getting is the following:
Execute failed: java.io.IOException: Cannot run program "webpack.cmd": CreateProcess error=2, The system cannot find the file specified
webpack.cmd needs to run in a command shell. Try...
<exec executable="cmd" failonerror="true">
<env key="PROD_ENV" value="true"/>
<arg value="/c"/>
<arg value="webpack.cmd"/>
</exec>
You may need to provide the full absolute path to webpack.cmd so cmd.exe can find it.

What does the "-c" mean in an ant exec task?

These are two ant tasks:
<target name="hg.add" >
<exec dir="." executable="hg">
<arg line="add ${reports-summary}" />
</exec>
</target>
<target name="hg.add">
<exec executable="/bin/sh">
<arg value="-c"/>
<arg value="hg add ${reports-summary}"/>
</exec>
</target>
This two tasks seem to have the same function. But why the second one needs to write"/bin/sh" and "-c"?
The -c is just an argument to the executable it does not mean anything special to the ant exec task.
The first target is running the hg executable directly.
The second target is running the Linux/Unix shell command (/bin/sh) and passing it the -c argument which tells the shell to execute a command given in the next argument. So this will run the same command as the first target, but the shell command may set up things like environment variables before running the command.

How to run ruby script as a task from ant build?

I have an exiting ant build that is called via ant -lib lib -f test_build.xml
I wanted to add one more <target> section to be run after the existing one finishes. I did some research and found ant manual for exec and even a question here on SO. After some reading I added new target to this existing build but it didn't work.
I tried to create new build file only with my target. It doesn't work either. Although the ant run finishes with message BUILD SUCCESSFUL
Total time: 0 seconds
If I run my ruby script from a command line it works. I tried to create bat file that would call my ruby script with the same result. If I call the bat file from dos window it works.
My ant run build file looks like
<project name="RunRubyExample">
<target name="calling ruby " >
<exec executable="ruby.exe">
<arg value="C:\EduTester\others\afterant.rb 1 2 tri four"/>
</exec>
</target>
<target name="calling batach">
<exec executable="cmd">
<arg value="/c"/>
<arg value="C:\EduTester\others\rubruby.bat 1 2 tri four"/>
</exec>
</target>
</project>
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
on Windows XP
It looks like you're passing a single arg value with embedded spaces
<arg value="C:\EduTester\others\afterant.rb 1 2 tri four"/>
Is that right? Or should it be either an arg line:
<arg line="C:\EduTester\others\afterant.rb 1 2 tri four"/>
or multiple arg values:
<arg value="C:\EduTester\others\afterant.rb"/>
<arg value="1"/>
<arg value="2"/>
<arg value="tri"/>
<arg value="four"/>
There needs to be specified target that needs to be run
either by <project name="RunRubyExample" default="callingruby">
or when calling the ant build file. Where we pass the target name we want to be run as an argument. ant -lib lib callingruby
Writing a Simple Buildfile
Thank you #Steve

Execute command in new window with Ant from IDEA

In IntelliJ IDEA I have this task in my Ant script
<target name="emulator-logcat">
<exec command="adb" spawn="false" osfamily="windows">
<arg value="-e"/>
<arg value="shell"/>
<arg value="logcat"/>
</exec>
</target>
It works but command output sent to IDEA ant window, not in Windows console window. How i can forward command output into new Windows console window as if i start this command from cmd.exe?
Problem resolved:
I create runner.bat file witch contains %* and call it like this
<target name="emulator-logcat">
<exec command="cmd.exe" spawn="true" osfamily="windows">
<arg line="/c start runner.bat adb -e shell logcat"/>
</exec>
</target>

Running a .cmd file from Ant

Is it possible to run a command (.cmd file) from Ant? Would I need to write Java code for this?
<exec executable="cmd" os="Windows XP">
<arg value="/C"/>
<arg value="command to run"/>
</exec>
You can do this by using the exec task. From the ant exec documentation:
Note that .bat files cannot in general by executed directly. One normally needs to execute the command shell executable cmd using the /c switch.
So you would need to do something like:
<exec executable="cmd">
<arg value="/c"/>
<arg value="batchfile.cmd"/>
</exec>
Note that by doing this you have created a dependency of running your ant script in windows.
Adding to eradicus answer, you can also execute .bat, .cmd, ... from any directory with argument on your Window machine by
<target name="test">
<exec executable="cmd" dir="C:/Users/mydir/">
<arg value="/C" />
<arg value="myjob.bat arg1 arg2" />
</exec>
</target>

Resources