We help IT Professionals succeed at work.

Ant script from DOS prompt

t3ch
t3ch asked
on
I have a build file that genereates an EAR file. This build file is executed within RAD and it used a RAD specific ANT task called "earExport". I have couple of questions on this:
I read on some other forums that its WAS/RAD specific task and If you want to execute the script outside of RAD you have to make use of RAD's JRE. My question is, how do I run this ant script build-myapp.xml from DOS prompt using my RAD's JRE and make use of Properties file as well? (properties file is in the same folder as ant script)
Other info:

JAVA_HOME is set to
C:\Program Files\Java\jdk1.6.0_28

 ANT_HOME is set to
C:\ant1.8\ant
 
RAD's JRE location is
C:\Program Files\IBM\RAD7\runtimes\base_v7\java\jre  

Build Script Location:
C:\myProject\BuildScript\build-myProject.xml
C:\myProject\BuildScript\build-myProject.properties
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
What happens with the following?
ant -f C:\myProject\BuildScript\build-myProject.xml  -p

Open in new window

Awarded 2011
Awarded 2011
Commented:
You make sure that

C:\Program Files\IBM\RAD7\runtimes\base_v7\java\jre\bin

is in the path before any other java

I guess this way:

ant -buildfile  C:\myProject\BuildScript\build-myProject.xml   -propertyfile C:\myProject\BuildScript\build-myProject earExport

Author

Commented:
Hello CEHJ,

                  It printed the two targets defined in ant script. I am trying to print a property from properties file, it only printed the key not the value.

Author

Commented:
Hi for_yan, I got this with your command:

BUILD FAILED
Target "earExport" does not exist in the project "<PROJECT_NAME>".
Awarded 2011
Awarded 2011

Commented:
do you have such target in the build.xml ?
CERTIFIED EXPERT
Top Expert 2016

Commented:
If you do

cd C:\myProject\BuildScript\
ant -f build-myProject.xml

you might have more success actually
Awarded 2011
Awarded 2011

Commented:
which targets did it print?

there should be target in the end of this ccommand

ant -buildfile  C:\myProject\BuildScript\build-myProject.xml   -propertyfile C:\myProject\BuildScript\build-myProject target_name

Author

Commented:
I am dealing with this issue here :

http://www.coderanch.com/t/108223/tools/earExport-within-RAD

and working on this solution:

"Hi Ugur Sipahi ,
to run the RAD ant tasks you need to run the task on the same JRE as the RAD , you can do this by select Run Ant .... from ant view this will open Ant proparty page in the JRE tap select run on the same JRE"
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>and If you want to execute the script outside of RAD you have to make use of RAD's JRE.

I'm not sure why that would be the case. What happened when you tried my last suggestion?

Author

Commented:
@ CEHJ,

         This is what I got with your second suggestion:


Wed 11/02/2011 15:35:55.46
C:\myProject\BuildScript>ant -f build-myProject.xml
Buildfile: C:\myProject\BuildScript\bbuild-myProject.xml
     [echo] ---- EAR Workspace location set ----
     [echo] C:\myProject
     [echo] C:\myProject\myProject_ear
     [echo] ${drop.location}
     [echo] ---- Before init ----
     [echo] ---- target cleanup started ----
     [echo] ---- target cleanup ended ----

BUILD SUCCESSFUL
Total time: 0 seconds

Author

Commented:
>> I'm not sure why that would be the case. What happened when you tried my last suggestion?

Because they are saying earExport is specific to WAS? Any doesnt know about this tag?
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>BUILD SUCCESSFUL

That looks ok to me ...

Author

Commented:
But it isnt. It took 0 seconds to build and I didnt get the EAR in drop location.
Awarded 2011
Awarded 2011

Commented:

>Because they are saying earExport is specific to WAS? Any doesnt know about this tag?

Taht may make sense - what target names do you have in C:\myProject\BuildScript\build-myProject.xml   ?
CERTIFIED EXPERT
Top Expert 2016

Commented:
I see the echo isn't working, but is that important? If so, try doing the following first, before the last commands i gave you

set JAVA_HOME="C:\Program Files\IBM\RAD7\runtimes\base_v7\java"

CERTIFIED EXPERT
Top Expert 2016

Commented:
>Because they are saying earExport is specific to WAS?

That's really nothing to do with Java versions. It will be to do with Ant and taskdefs
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>But it isnt. It took 0 seconds to build and I didnt get the EAR in drop location.

Better attach the build file and properties file if you can
Awarded 2011
Awarded 2011

Commented:
print C:\myProject\BuildScript\build-myProject.xml and look waht targets are specified there

Author

Commented:
@ CEHJ, After this set JAVA_HOME I am getting:

Files\IBM\RAD7\runtimes\base_v7\java"" was unexpected at this time.

Author

Commented:
Let me post the build file for you guys
CERTIFIED EXPERT
Top Expert 2016

Commented:
What COULD make a difference is if ANT_HOME is something quite different as far as WAS is concerned. earExport needs to be supported by the libraries in Ant's classpath.

If you're still having difficulties, run the following and attach the file ant.log in the current directory to your next post


ant -d -f build-myProject.xml >ant.log 2>&1

Open in new window

CERTIFIED EXPERT
Top Expert 2016

Commented:
>>Files\IBM\RAD7\runtimes\base_v7\java"" was unexpected at this time.

Looks like the quoting could have been wrong

Author

Commented:
Content of properties file:

project.name=BuildMyProjectEAR
drop.location=C:\EAR_DROP_LOCATION\Build
build-myProject.xml
Awarded 2011
Awarded 2011

Commented:
I think if you say -k it should eexecute all targets

ant -buildfile  C:\myProject\BuildScript\build-myProject.xml   -propertyfile C:\myProject\BuildScript\build-myProject  -k
Awarded 2011
Awarded 2011

Commented:
but maybe you don;t want all of them


ant -buildfile  C:\myProject\BuildScript\build-myProject.xml   -propertyfile C:\myProject\BuildScript\build-myProject.properties service-build-local-copy

Author

Commented:
Result of:

ant -d -f build-myProject.xml >ant.log 2>&1


 
ant.log
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>Unable to find property file: C:\myProject\build-myProject.properties

That doesn't seem to be present
CERTIFIED EXPERT
Top Expert 2016

Commented:
So you might try the following before you run it again
copy C:\myProject\BuildScript\build-myProject.properties  C:\myProject

Open in new window

Author

Commented:
But its in the same folder. How do I fix it?
Awarded 2011
Awarded 2011

Commented:

try adding  this to the command  
 -propertyfile C:\myProject\BuildScript\build-myProject.properties
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>But its in the same folder. How do I fix it?

It's not the same folder. The build file is looking in C:\myProject

You have it (afaik) in C:\myProject\BuildScript

Author

Commented:
@CEHJ, tried copying it and then ran your command.. Still 0 Second build successful :(
CERTIFIED EXPERT
Top Expert 2016
Commented:
If there are only two lines in the properties file anyway, you might as well do (assuming it's the 'local-service' target you want)
ant -f build-myProject.xml -Dproject.name=BuildMyProjectEAR -Ddrop.location=C:\EAR_DROP_LOCATION\Build local-service

Open in new window

CERTIFIED EXPERT
Top Expert 2016

Commented:
>>@CEHJ, tried copying it and then ran your command.. Still 0 Second build successful :(

On each occasion it fails, re-run it with the following and post the result
ant -d <previous failed command - no angle brackets, obviously> >ant.log 2>&1

Open in new window

Author

Commented:
At least this time I got a different error, on passion arguments from command line as suggested by CEHJ

Buildfile: C:\myProject\build-myProject.xml
     [echo] ---- EAR Workspace location set ----
     [echo] C:\myProject
     [echo] C:\myProject\PremierProviderWeb_ear
     [echo] C:\EAR_DROP_LOCATION\Build
     [echo] ---- Before init ----
     [echo] ---- target cleanup started ----
     [echo] ---- target cleanup ended ----

local-service:
     [echo] Change the Timestamps
     [echo] Build Ear to the local directory
   [delete] Deleting: C:\myProject\premierproviderweb.ear

BUILD FAILED
C:\myProject\build-myProject.xml:68: Problem: failed to create task or type earExport
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.


Total time: 1 second

Author

Commented:
Here: http://www.coderanch.com/t/108223/tools/earExport-within-RAD
Someone suggested:

"earExport is a task provided with RAD 6.0. Since it's not a core part of ant, you have to define a taskdef tag to point to it. I don't have the path information for that tag on hand, but I imagine it is in the RAD 6 help.

This isn't necessary within RAD 6 because the tool automatically includes it in the classpath."

How can we try this?
CERTIFIED EXPERT
Top Expert 2016

Commented:
That would possibly be connected with http:#37073035 but please apply http#:37073270
CERTIFIED EXPERT
Top Expert 2016

Commented:
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>Someone suggested:

That's what i said at http:#37073035 

A much better solution would be to copy the supporting libraries into Ant, then you wouldn't be dependent on RAD

Author

Commented:
Attached log
ant.log

Author

Commented:
CEHJ, Simplest way to do so?
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>Attached log

You've gone backwards there. Those are the previous errors. The errors you 'want' are the ones relating to taskdef. Never mind about it now

>>Simplest way to do so?

You need to

a. discover which jar(s) support earExport
b. copy them to %ANT_HOME%\lib

Author

Commented:
ok Thanks. I am going to try that and post results here. Please keep an eye on this thread.
CERTIFIED EXPERT
Top Expert 2016

Commented:
Your link:

>><taskdef name="earExport" classname="com.ibm.etools.j2ee.ant.EARExport" classpath="antj2ee.jar" />

Gives the class name but a fairly nondescript-sounding jar. See if that jar is in WAS's libraries

CERTIFIED EXPERT
Top Expert 2016

Commented:
If


jar tf antj2ee.jar | find "EARExport"

then you should be in with a chance

Author

Commented:
Hi CEHJ,

            Found the jar file and added it to Ant's lib but still getting a 0 second build.

Author

Commented:
This is what I am getting after dropping the jar file:

I also added this taskdef:
<taskdef name="earExport" classname="com.ibm.etools.j2ee.ant.EARExport" classpath="antj2ee.jar" />

Wed 11/02/2011 21:11:59.14
C:\myProject>ant -f build-myProject.xml
Buildfile: C:\myProject\build-myProject.xml
     [echo]
     [echo]
     [echo]
     [echo]

BUILD FAILED
C:\myProject\build-myProject.xml:13: taskdef A class needed by class com.ibm.etools.j2ee.ant.EARExport can
not be found: org/eclipse/core/commands/ExecutionException
 using the classloader AntClassLoader[C:\myProject\antj2ee.jar]

Total time: 0 seconds
CERTIFIED EXPERT
Top Expert 2016

Commented:
Very good of them to give you such a clear error message. You need to find org/eclipse/core/commands/ExecutionException and add that jar too.

btw what does earExport actually DO?
CERTIFIED EXPERT
Top Expert 2016
Commented:
In my system, that class is in /usr/lib/eclipse/plugins/org.eclipse.core.commands_3.2.0.I20060605-1400.jar

Author

Commented:
Hi CEHJ,

     >> what does earExport actually DO?

It basically, exports all the projects in your workspace as an EAR file.
CERTIFIED EXPERT
Top Expert 2016

Commented:
Ah, that would explain the dependency on an Eclipse jars. It could have others too

Author

Commented:
Whats the other way to accomplish the same? I meant to create an EAR of your workspace.
CERTIFIED EXPERT
Top Expert 2016

Commented:
I think to do it properly would require a custom task, and that's probably why it exists

Author

Commented:
Hmmm... any example packing multiple projects into one EAR? Is it possible to see "how RAd builds it behind the scenes?"
CERTIFIED EXPERT
Top Expert 2016

Commented:
Well you've gone from wanting to get it working to wanting to rewrite it - they are two different things ;) The best way to find out is to get the source

Author

Commented:
lol.. I think rewriting would be lot better and flexible approach. We can run the same script on diff env.

>> The best way to find out is to get the source

  You mean EAR source?
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>You mean EAR source?

No - the source of the earExport Ant task. I really don't see the point of reinventing it.

>>We can run the same script on diff env.

That should be possible anyway

Author

Commented:
ok so first task is to see what earExport does.
CERTIFIED EXPERT
Top Expert 2016

Commented:
Well i'm getting confused now, as i thought your requirement was to get it working and use it
CERTIFIED EXPERT
Top Expert 2016

Commented:
:)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.