Solved

help needed in ant

Posted on 2004-08-13
17
514 Views
Last Modified: 2013-11-23
I am trying to use ant to be able to compile java files.
Installed ant in d:\ant
set ant_home and path.

Copied my source files to d:\ant\src (it contains packages)

Made build.xml file in ant folder

<?xml version="1.0" encoding="UTF-8"?>

<project name="M" default="release" basedir=".">
    <description>simple example build file
    </description>

  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="release"  location="release"/>

  <target name="init">
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}"/>
  </target>

  <target name="release" depends="compile"
        description="generate the release" >
    <!-- Create the release directory -->
    <mkdir dir="${release}/lib"/>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${release}/lib/M.jar" basedir="${build}">
      <manifest>
        <attribute name="Implementation-Title" value="com.p1.p2.main"/>
        <attribute name="Implementation-Vendor" value="Me Inc."/>
        <attribute name="Implementation-Version" value="1.0"/>
        <attribute name="Main-Class" value="com.p1.p2.main.App"/>
      </manifest>
    </jar>
  </target>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} and ${release} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${release}"/>
  </target>
</project>

wrote ant on prompt
got the following error message

Buildfile: build.xml does not exist!
Build failed

0
Comment
Question by:thomas908
  • 7
  • 5
  • 2
  • +3
17 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11791875
Did you cd to the directory build.xml is in first?
0
 
LVL 8

Author Comment

by:thomas908
ID: 11791909
I have JBuilder a as well. Will it be easier using JBuilder
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11791920
If you don't want to cd you can specify it:

ant -buildfile \java\build.xml test
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 86

Expert Comment

by:CEHJ
ID: 11791934
>>Will it be easier using JBuilder

It's always better to use open and generic software, such as Ant. What's the problem in changing directory?
0
 
LVL 8

Author Comment

by:thomas908
ID: 11791937
sorry.
Got rid of the earlier error.
But its unable to find the jar files i user in my java classes.
When i compiled from prompt i used to set the classapth as

D:\M\src>javac -classpath ..\log4j-1.2.7.jar;.;..\mysql-connector-java-3.0.6-st
able-bin.jar;..\conf.jar;..\datasocket.jar;..\photos.jar;..\jsearch.jar;..\jhall
.jar;..\jhbasic.jar;..\jh.jar;..\thirdparty\xercesImpl.jar;..\thirdparty\xmlPars
erAPIs.jar; com\p1\p2\main\*.java

what should i do here?
0
 
LVL 6

Expert Comment

by:expertmb
ID: 11791940
you can use jbuilder(or ide which you can plugin ant). have you checked the file in that folder.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11791950
>>what should i do here?

Ant will use the classpath, so you can do the same
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 350 total points
ID: 11791976
You can also set paths inside the build.xml too:

http://ant.apache.org/manual/using.html

(see 'Path-like Structures')
0
 
LVL 8

Author Comment

by:thomas908
ID: 11791977
Something like

    <jar jarfile="${release}/lib/MT.jar" basedir="${build}">
      <manifest>
        <attribute name="Implementation-Title" value="com.dassault.mt.main"/>
        <attribute name="Implementation-Vendor" value="Me Inc."/>
        <attribute name="Implementation-Version" value="1.0"/>
        <attribute name="Main-Class" value=" -classpath ..\log4j-1.2.7.jar;.;..\mysql-connector-java-3.0.6-stable-bin.jar;..\conf.jar;..\datasocket.jar;..\photos.jar;..\jsearch.jar;..\jhall.jar;..\jhbasic.jar;..\jh.jar;..\thirdparty\xercesImpl.jar;..\thirdparty\xmlParserAPIs.jar; com\dassault\mt\main\*.java com.p1.p2.main.App"/>
      </manifest>
    </jar>

But still unable to find jar files
0
 
LVL 8

Author Comment

by:thomas908
ID: 11791980
Something like

    <jar jarfile="${release}/lib/MT.jar" basedir="${build}">
      <manifest>
        <attribute name="Implementation-Title" value="com.p1.p2.main"/>
        <attribute name="Implementation-Vendor" value="Me Inc."/>
        <attribute name="Implementation-Version" value="1.0"/>
        <attribute name="Main-Class" value=" -classpath ..\log4j-1.2.7.jar;.;..\mysql-connector-java-3.0.6-stable-bin.jar;..\conf.jar;..\datasocket.jar;..\photos.jar;..\jsearch.jar;..\jhall.jar;..\jhbasic.jar;..\jh.jar;..\thirdparty\xercesImpl.jar;..\thirdparty\xmlParserAPIs.jar; com\dassault\mt\main\*.java com.p1.p2.main.App"/>
      </manifest>
    </jar>

But still unable to find jar files
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11792000
What task are you actually intending to perform with Ant?
0
 
LVL 4

Assisted Solution

by:astorer
astorer earned 50 total points
ID: 11792214
No, you should not be changing the <jar> element for the classpath.  The jar element takes the compiled class files and puts them into a jar - no need for classpath here.
You need to set the classpath used for compilation.
So, as part of your global properties at the top, have
 <property name="myclasspath" value="..\log4j-1.2.7.jar;.;..\mysql-connector-java-3.0.6-stable-bin.jar;..\conf.jar;..\datasocket.jar;..\photos.jar;..\jsearch.jar;..\jhall.jar;..\jhbasic.jar;..\jh.jar;..\thirdparty\xercesImpl.jar;..\thirdparty\xmlParserAPIs.jar"/>

Then instead of:
    <javac srcdir="${src}" destdir="${build}"/>

Try:
    <javac srcdir="${src}" destdir="${build}" classpath="${myclasspath}"/>

Note also that you would not put com\dassault\mt\main\*.java com.p1.p2.main.App on the classpath explicitly.  Rather, you would put the parent directory on the classpath.  That is the directory containing "com".

HTH
Andrew
0
 
LVL 8

Author Comment

by:thomas908
ID: 11792526
>>What task are you actually intending to perform with Ant?


http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21092469.html
0
 
LVL 27

Assisted Solution

by:rrz
rrz earned 50 total points
ID: 11793535
I agree with astorer.
Also, you could create a log file to help debuging.

  <target name="compile" depends="init"
        description="compile the source " >
    <record name="my.log" loglevel="debug" action="start" append="false"/>
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}" classpath="${myclasspath}"/>
  </target>
0
 
LVL 92

Assisted Solution

by:objects
objects earned 50 total points
ID: 11797936
Copy all your jars to your jdk's ext directory. That way they will get picked up automatically.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11800389
8-)
0
 
LVL 92

Expert Comment

by:objects
ID: 11802187
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question