java build problem

I need a help with Ant  build

I have a folder called  "c:\myapps" . This folder contains "project1" folder and "project2" folder.

"project1\build.xml"  ----> builds "project1"  .

"project2\Apps\build.xml"   ----> builds "project2".


However, I dont wish to run them individually and so I need a FINAL build.xml to be present in folder "c:\myapps" which will help me to build all projects once.


Basically , I would like to invoke the final build.xml this way
c:\myapps\ant --> This will build all projects

How do I import the two build.xml into Final build.xml ?  I'm worried about  file paths .

cofactorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

colr__Commented:
Not answering your question, but you might want to consider using maven instead for this. While Ant was good in it's day, it has now been pretty much superseded industry-wide by Maven. Maven handles this type of thing naturally with a parent project structure.
0
ioantonCommented:
Your final build.xml should look like the one below (of course, it might be extended by adding new targets):

<project basedir="." default="build" name="final-build">

      <target name="build">            
            <iterate target="build"/>
      </target>

        <macrodef name="iterate">
            <attribute name="target" default=""/>
            <sequential>
                <subant target="@{target}">
                      <fileset dir=".">
                                <include name="*/build.xml"/>
                                <include name="*/Apps/build.xml"/>
                        </fileset>
                </subant>
            </sequential>
      </macrodef>
</project>
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

cofactorAuthor Commented:
@for_yan ,

I have gone thorugh your link and I have come up with this

<?xml version="1.0" ?>
 <project name="myapps" default="all">
<target name="all" depends="app1, app2" />

<target name="app1">
    <ant buildfile="project1/build.xml" target="war" />        
</target>

<target name="app2">
    <ant buildfile="project2/Apps/build.xml" target="ear" />        
</target>
 </project>

Open in new window


This does not work . It throws Error "ant doesn't support the "buildfile" attribute."

my Ant version: Apache Ant version 1.7.0

how do I fix this ?
0
cofactorAuthor Commented:
@ionaton,

I modified your code  but when I run your code I get this " [subant] No sub-builds to iterate on".

My default build  targers are "war" for project1  and "ear" for project2

I ALSO  tried this way ..but this too did not work.

<?xml version="1.0" ?>
 <project name="myapps" default="all">
<target name="all" depends="app1, app2" />

<target name="app1">
    <ant buildfile="project1/build.xml" target="war" />        
</target>

<target name="app2">
    <ant buildfile="project2/Apps/build.xml" target="ear" />        
</target>
 </project>

Open in new window

I get error  "ant doesn't support the "buildfile" attribute."  for this.

Do you see any workaround ? whats the solution ?
0
ioantonCommented:
Well, this works well only if all default targets have the same name. If you cannot do this, just replace the buildfile attribute with antfile in the other solution:

<target name="app1">
    <ant antfile="project1/build.xml" target="war" />        
</target>

<target name="app2">
    <ant antfile="project2/Apps/build.xml" target="ear" />        
</target>
0
msk_apkCommented:
ant -f <buildfile> can be used.

have a new build.xml with name say new.xml that invokes those two build.xml files as below

<import file="project/build.xml"/>
<antcall target="first_project_run" />
0
cofactorAuthor Commented:
>>Well, this works well only if all default targets have the same name.

No . I can not . one is for WAR and another is for EAR. they are separate projects.

>>If you cannot do this, just replace the buildfile attribute with antfile in the other solution:

I did this. But still it does not work . It throws error . it says it can not find the lib's now for project1.


Here is the updated content:

myapps/build.xml
------------------------
<?xml version="1.0" ?>
 <project name="myapps" basedir="." default="all">
<target name="all" depends="app1, app2" />
<target name="app1">
    <ant antfile="project1/build.xml" target="war" />        
</target>

<target name="app2">
    <ant antfile="project2/Apps/build.xml" target="ear" />        
</target>
 </project>


myapps/project1/build.xml
-------------------
<project name="project1" basedir="." default="war">
    <property name="src.dir"     value="src"/>
    <property name="jar.dir"     value="pmd-4.2.5/lib"/>
   ........................
   ........................


myapps/project2/Apps/build.xml
--------------------------------------------
 <project name="project2" default="ear">
   <property environment="env"/>

    <path id="compile.classpath">
       <fileset dir="WebContent/WEB-INF/lib">
          <include name="*.jar"/>
       </fileset>
        
         <pathelement location="serverlib/servlet-api.jar"/>
        
   </path>
   .............
   ..............

why the build still fails ? In final build  time  project1's  build.xml now unable to find lib folder from pmd-4.2.5/lib !
what happened ?  
0
ioantonCommented:
That's another problem. Please check the following:
1. Does the folder pmd-4.2.5/lib really exist? If not, create it.
2. Where is the pmd-4.2.5 located as against the basedir? It should be in the same folder, otherwise you have to change the value of the property "jar.dir" to point to the correct location
0
ioantonCommented:
Yet another suggestion: add the attribute

inheritAll="false"

to each of these calls:

<ant antfile="project1/build.xml" target="war" inheritAll="false"/>
<ant antfile="project2/Apps/build.xml" target="ear" inheritAll="false"/>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cofactorAuthor Commented:
>>>1. Does the folder pmd-4.2.5/lib really exist? If not, create it.

yes ..absolutely ..its there . its under  myapps/project1/pmd-4.2.5/lib

>>>2. Where is the pmd-4.2.5 located as against the basedir?

 its under myapps/project1/pmd-4.2.5/lib .

>>>It should be in the same folder,

what do you mean by same folder ?




0
ioantonCommented:
In the same folder with the build.xml file which refers it. Please follow the suggestion I made afterwards. This should do the trick.
0
cofactorAuthor Commented:
>>>Please follow the suggestion I made afterwards. This should do the trick.

Yes.This works ...happy.

By the way, what does inheritAll="false" is doing basically ? I dont understand the meaning of this attribute.

Could you please explain what its doing ?

Also please post the Ant doc link which explains particular attribute.
0
ioantonCommented:
The inheritAll attribute indicates whether you want or not to pass all properties available in the caller build.xml to the other, called build.xml. These properties include, among other things, the basedir, so if the attribute has the value "true" which is the default,  Ant looks for pmd-4.2.5 in the folder the caller build.xml resides in, i.e. myapps.
For details, check this: http://ant.apache.org/manual/Tasks/ant.html
0
cofactorAuthor Commented:
Excellent
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.