Solved

help needed in ant

Posted on 2004-08-13
17
532 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

635 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