Solved

help needed in ant

Posted on 2004-08-13
17
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iterator/ListIterator approach 17 68
Chrome and Firefox Java 5 88
printf performancy 11 102
jmeter usage 4 62
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.
Suggested Courses

734 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