You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Shawn Castrianni <Sh...@halliburton.com> on 2009/02/13 08:26:57 UTC

setup environment for java task

Let's say I have a series of setupEnv.bat files in my source repository that I need to execute as part of setting up my runtime environment before executing my java code with the java task.  I don't see an elegant way of doing this.  I could execute these bat files as part of my build.bat before invoking ant itself.  However, I don't like this approach as it would interfere with my build environment.  I only want it to affect my runtime environment when I launch java code from my build.xml.  For example, my "build.bat compile" command should not invoke the setupEnv.bat files, but my "build.bat launch" command should.  I don't want to start writing a lot of logic in my simple build.bat script which just launches ant to detect what target is being run to know whether to invoke the setupEnv.bat files.  I was hoping for something more elegant inside ANT itself.  The java task already provides a way to pass in environment variables, but I don't see how I could have it execute some bat files first to setup the environment.

Does anybody know of an elegant way of doing this or some 3rd party ant plugin that can do it?

I don't even know if it is possible in java.  You would have to somehow invoke a separate process and then feed it commands to run (like executing batch files) to setup its environment, and then pass it the JVM command line to finally invoke the java class.

---
Shawn Castrianni

----------------------------------------------------------------------
This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient.  Any review, use, distribution, or disclosure by others is strictly prohibited.  If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.

Re: AW: setup environment for java task

Posted by JohnBurrows <ne...@hotmail.com>.
So, basically it sounds like you are trying to setup some kind of smoke test
environment.

I suggest you decide how involved your build process will be and maybe break
it down into pieces to better manage it.

1) Build environment scripts:
      Such as your build.xml ant script that is kicked off from your
build.bat file
2) A properties file for your project to reflect what variables you want to
use for the build:
      Such as
               test.product=true

With the test.product variable set to anything, then in your build.xml you
can check the variable and if set, then run the target to setup and test
your product, IE:

<target name="install_and_test" if="${test.product}">
       <exec executable="cmd" failonerror="true" output="install.log">
                <arg line="/c PATH_TO_YOUR_INSTALL_BAT/install.bat
AND_ANYPARAMETERS_YOU_WANT_TO_PASS seperated by spaces, can be ${ANT
VARIABLES}"/>
       </exec>

       <exec executable="cmd" failonerror="true" output="test.log">
                <arg line="/c PATH_TO_YOUR_TEST_BAT/test.bat
AND_ANYPARAMETERS_YOU_WANT_TO_PASS seperated by spaces, can be ${ANT
VARIABLES}"/>
       </exec>
</target>

You can also use the ANT optional jars to use If/Then statements directly in
the ANT script and set the test.product to true or false and do something
different depending upon which value is entered:

 <target name="install_and_test">
       <if>
            <equals arg1="${test.product}" arg2="true" />
            <then>
                  <exec executable="cmd" failonerror="true"
output="install.log">
                        <arg line="/c PATH_TO_YOUR_INSTALL_BAT/install.bat
AND_ANYPARAMETERS_YOU_WANT_TO_PASS seperated by spaces, can be ${ANT
VARIABLES}"/>
                   </exec>

                   <exec executable="cmd" failonerror="true"
output="test.log">
                          <arg line="/c PATH_TO_YOUR_TEST_BAT/test.bat
AND_ANYPARAMETERS_YOU_WANT_TO_PASS seperated by spaces, can be ${ANT
VARIABLES}"/>
                    </exec>
            </then>
            <elseif>
            <equals arg1="${test.product}" arg2="false" />
                <then>
                          DO SOMETHING ELSE
                </then>
            </elseif>
            <else>
                <fail>Invalid value entered for test.product property in
build.properties file.</fail>
            </else> 
        </if>
    </target>

Of course you can always just use the -Dtest.product=true command line input
for the variable instead of using a properties file.

Just put your multiple batch files that you want to run into one batch file
and that is the one to call/run from ANT:

MY_BATCH_FILE.BAT
@echo off
call 1st_batch_file.cmd or .bat
call 2st_batch_file.cmd or .bat
call 3st_batch_file.cmd or .bat
exit

Above uses call if you want it to wait for each one to finish before moving
forward with the next.

John


Hello, 

There are some interseting arguments to exec like spawn (standard is false)
etc.
I never tried this, so someone else might know exactly.

But I think it is worth a try to use the exec task for a test and see what
happens.
I think it is possible to keep the settings of a Batchfile you run.

Greetings

-- 
Jürgen Knuplesch                    

Geschäftsführer: Uwe Seltmann
HRB Stuttgart 17655
USt-IdNr.: DE 811944121 
-----Ursprüngliche Nachricht-----
Von: Shawn Castrianni [mailto:Shawn.Castrianni@halliburton.com] 
Gesendet: Freitag, 13. Februar 2009 09:36
An: 'Ant Users List'
Betreff: RE: setup environment for java task

Thanks for the suggestion, but here is my problem:

1. These batch files are used at runtime from an end user after installing
the product with an installer.
2. Therefore, these batch files cannot be converted to ANT as that would
duplicate the logic and could get out of sync 3. I am trying to recreate an
end user's runtime environment with ANT so that I can launch our application
or run unit tests with the same environment which is why I want to execute
those same batch files 4. executing each batch file in an exec task only
affects the process spawned by the exec task and is not remembered from one
batch file to the next so when I finally launch my java class, that
environment from the batch files is already gone, I think

---
Shawn Castrianni
-- 
View this message in context: http://www.nabble.com/setup-environment-for-java-task-tp21991537p22728095.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: setup environment for java task

Posted by "Knuplesch, Juergen" <Ju...@icongmbh.de>.
Hello, 

There are some interseting arguments to exec like spawn (standard is false) etc.
I never tried this, so someone else might know exactly.

But I think it is worth a try to use the exec task for a test and see what happens.
I think it is possible to keep the settings of a Batchfile you run.

Greetings

-- 
Jürgen Knuplesch                    

Geschäftsführer: Uwe Seltmann
HRB Stuttgart 17655
USt-IdNr.: DE 811944121 
-----Ursprüngliche Nachricht-----
Von: Shawn Castrianni [mailto:Shawn.Castrianni@halliburton.com] 
Gesendet: Freitag, 13. Februar 2009 09:36
An: 'Ant Users List'
Betreff: RE: setup environment for java task

Thanks for the suggestion, but here is my problem:

1. These batch files are used at runtime from an end user after installing the product with an installer.
2. Therefore, these batch files cannot be converted to ANT as that would duplicate the logic and could get out of sync 3. I am trying to recreate an end user's runtime environment with ANT so that I can launch our application or run unit tests with the same environment which is why I want to execute those same batch files 4. executing each batch file in an exec task only affects the process spawned by the exec task and is not remembered from one batch file to the next so when I finally launch my java class, that environment from the batch files is already gone, I think

---
Shawn Castrianni


-----Original Message-----
From: Knuplesch, Juergen [mailto:Juergen.Knuplesch@icongmbh.de]
Sent: Friday, February 13, 2009 2:05 AM
To: Ant Users List
Subject: AW: setup environment for java task

 Hello,

I would translate the "bat" files to ANT-Tasks.
This is a lot of work, but than your Antfile can decide what bat-jobs you run and when.

Another way is to run the bat-files itself inside Ant using the exec-task, which is a bit tricky to handle.

To be honest: I dont like Batchfiles, so I would prefer "translating" the stuff to Ant, so that I have the control out of Ant.
But maybe, if you need the Batchfiles as well, then you produce redundancy, if you translate it to Ant.

Greetings

Juergen


--
Jürgen Knuplesch
-----Ursprüngliche Nachricht-----
Von: Shawn Castrianni [mailto:Shawn.Castrianni@halliburton.com]
Gesendet: Freitag, 13. Februar 2009 08:27
An: 'Ant Users List'
Betreff: setup environment for java task

Let's say I have a series of setupEnv.bat files in my source repository that I need to execute as part of setting up my runtime environment before executing my java code with the java task.  I don't see an elegant way of doing this.  I could execute these bat files as part of my build.bat before invoking ant itself.  However, I don't like this approach as it would interfere with my build environment.  I only want it to affect my runtime environment when I launch java code from my build.xml.  For example, my "build.bat compile" command should not invoke the setupEnv.bat files, but my "build.bat launch" command should.  I don't want to start writing a lot of logic in my simple build.bat script which just launches ant to detect what target is being run to know whether to invoke the setupEnv.bat files.  I was hoping for something more elegant inside ANT itself.  The java task already provides a way to pass in environment variables, but I don't see how I could have it execute some bat files first to setup the environment.

Does anybody know of an elegant way of doing this or some 3rd party ant plugin that can do it?

I don't even know if it is possible in java.  You would have to somehow invoke a separate process and then feed it commands to run (like executing batch files) to setup its environment, and then pass it the JVM command line to finally invoke the java class.

---
Shawn Castrianni

----------------------------------------------------------------------
This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient.  Any review, use, distribution, or disclosure by others is strictly prohibited.  If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: setup environment for java task

Posted by Shawn Castrianni <Sh...@halliburton.com>.
Thanks for the suggestion, but here is my problem:

1. These batch files are used at runtime from an end user after installing the product with an installer.
2. Therefore, these batch files cannot be converted to ANT as that would duplicate the logic and could get out of sync
3. I am trying to recreate an end user's runtime environment with ANT so that I can launch our application or run unit tests with the same environment which is why I want to execute those same batch files
4. executing each batch file in an exec task only affects the process spawned by the exec task and is not remembered from one batch file to the next so when I finally launch my java class, that environment from the batch files is already gone, I think

---
Shawn Castrianni


-----Original Message-----
From: Knuplesch, Juergen [mailto:Juergen.Knuplesch@icongmbh.de]
Sent: Friday, February 13, 2009 2:05 AM
To: Ant Users List
Subject: AW: setup environment for java task

 Hello,

I would translate the "bat" files to ANT-Tasks.
This is a lot of work, but than your Antfile can decide what bat-jobs you run and when.

Another way is to run the bat-files itself inside Ant using the exec-task, which is a bit tricky to handle.

To be honest: I dont like Batchfiles, so I would prefer "translating" the stuff to Ant, so that I have the control out of Ant.
But maybe, if you need the Batchfiles as well, then you produce redundancy, if you translate it to Ant.

Greetings

Juergen


--
Jürgen Knuplesch
-----Ursprüngliche Nachricht-----
Von: Shawn Castrianni [mailto:Shawn.Castrianni@halliburton.com]
Gesendet: Freitag, 13. Februar 2009 08:27
An: 'Ant Users List'
Betreff: setup environment for java task

Let's say I have a series of setupEnv.bat files in my source repository that I need to execute as part of setting up my runtime environment before executing my java code with the java task.  I don't see an elegant way of doing this.  I could execute these bat files as part of my build.bat before invoking ant itself.  However, I don't like this approach as it would interfere with my build environment.  I only want it to affect my runtime environment when I launch java code from my build.xml.  For example, my "build.bat compile" command should not invoke the setupEnv.bat files, but my "build.bat launch" command should.  I don't want to start writing a lot of logic in my simple build.bat script which just launches ant to detect what target is being run to know whether to invoke the setupEnv.bat files.  I was hoping for something more elegant inside ANT itself.  The java task already provides a way to pass in environment variables, but I don't see how I could have it execute some bat files first to setup the environment.

Does anybody know of an elegant way of doing this or some 3rd party ant plugin that can do it?

I don't even know if it is possible in java.  You would have to somehow invoke a separate process and then feed it commands to run (like executing batch files) to setup its environment, and then pass it the JVM command line to finally invoke the java class.

---
Shawn Castrianni

----------------------------------------------------------------------
This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient.  Any review, use, distribution, or disclosure by others is strictly prohibited.  If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: setup environment for java task

Posted by "Knuplesch, Juergen" <Ju...@icongmbh.de>.
 Hello,

I would translate the "bat" files to ANT-Tasks.
This is a lot of work, but than your Antfile can decide what bat-jobs you run and when.

Another way is to run the bat-files itself inside Ant using the exec-task, which is a bit tricky to handle.

To be honest: I dont like Batchfiles, so I would prefer "translating" the stuff to Ant, so that I have the control out of Ant.
But maybe, if you need the Batchfiles as well, then you produce redundancy, if you translate it to Ant.

Greetings

Juergen


-- 
Jürgen Knuplesch
-----Ursprüngliche Nachricht-----
Von: Shawn Castrianni [mailto:Shawn.Castrianni@halliburton.com] 
Gesendet: Freitag, 13. Februar 2009 08:27
An: 'Ant Users List'
Betreff: setup environment for java task

Let's say I have a series of setupEnv.bat files in my source repository that I need to execute as part of setting up my runtime environment before executing my java code with the java task.  I don't see an elegant way of doing this.  I could execute these bat files as part of my build.bat before invoking ant itself.  However, I don't like this approach as it would interfere with my build environment.  I only want it to affect my runtime environment when I launch java code from my build.xml.  For example, my "build.bat compile" command should not invoke the setupEnv.bat files, but my "build.bat launch" command should.  I don't want to start writing a lot of logic in my simple build.bat script which just launches ant to detect what target is being run to know whether to invoke the setupEnv.bat files.  I was hoping for something more elegant inside ANT itself.  The java task already provides a way to pass in environment variables, but I don't see how I could have it execute some bat files first to setup the environment.

Does anybody know of an elegant way of doing this or some 3rd party ant plugin that can do it?

I don't even know if it is possible in java.  You would have to somehow invoke a separate process and then feed it commands to run (like executing batch files) to setup its environment, and then pass it the JVM command line to finally invoke the java class.

---
Shawn Castrianni

----------------------------------------------------------------------
This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient.  Any review, use, distribution, or disclosure by others is strictly prohibited.  If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org