help needed in ant

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

LVL 8
thomas908Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
CEHJConnect With a Mentor Commented:
You can also set paths inside the build.xml too:

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

(see 'Path-like Structures')
0
 
CEHJCommented:
Did you cd to the directory build.xml is in first?
0
 
thomas908Author Commented:
I have JBuilder a as well. Will it be easier using JBuilder
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
CEHJCommented:
If you don't want to cd you can specify it:

ant -buildfile \java\build.xml test
0
 
CEHJCommented:
>>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
 
thomas908Author Commented:
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
 
expertmbCommented:
you can use jbuilder(or ide which you can plugin ant). have you checked the file in that folder.
0
 
CEHJCommented:
>>what should i do here?

Ant will use the classpath, so you can do the same
0
 
thomas908Author Commented:
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
 
thomas908Author Commented:
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
 
CEHJCommented:
What task are you actually intending to perform with Ant?
0
 
astorerConnect With a Mentor Commented:
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
 
thomas908Author Commented:
>>What task are you actually intending to perform with Ant?


http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21092469.html
0
 
rrzConnect With a Mentor Commented:
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
 
objectsConnect With a Mentor Commented:
Copy all your jars to your jdk's ext directory. That way they will get picked up automatically.
0
 
CEHJCommented:
8-)
0
 
objectsCommented:
0
All Courses

From novice to tech pro — start learning today.