Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

help needed in ant

Posted on 2004-08-13
17
Medium Priority
?
537 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
PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

 
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 1400 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 200 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 28

Assisted Solution

by:rrz
rrz earned 200 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 200 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

Technology Partners: 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!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

715 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