aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Simple Ant Build Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Simple Ant Build" Watch "Simple Ant Build" New topic
Author

Simple Ant Build

saurav sarkar
Ranch Hand

Joined: Jan 07, 2007
Posts: 180

Dear All,

I have a simple build file as follows



I am getting this error in the Eclipse console

BUILD FAILED
Target `bin' does not exist in this project.

Whereas i am having a bin folder, and i am having the java files
under the C:\saurav\proj.

Please help.


Be Objectively Oriented.Explore the power of OOPs.
My Blog, Eclipse EMF Query committer.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

I recommend you don't use backslashes in filenames in Java and java-based systems such as Ant. Backslashes are not only OS-specific, they're also often interpreted as escape characters, leading to unexpected results. You can do this instead:


Or, better still:


Also, it's not a good idea to embed your output directory inside your source directory. Make a separate source directory in its own separater subtree. It makes it harder to accidentally delete all your source code and you don't run into unpleasant surprises from tools such as Eclipse that automatically clean output directories.

Also, it looks lie you're keeping the Ant build.xml separate from your actual project. It's a good idea to keep the Ant build file inside your project directory (I keep it in the project root). That way if you want to transport your project to another machine - or use a source code management system - everything's in one place.


Customer surveys are for companies who didn't pay proper attention to begin with.
saurav sarkar
Ranch Hand

Joined: Jan 07, 2007
Posts: 180

Thanks Tim for the reply.

I have modified the build.xml like this


but still i am getting the same error.

I have kept the build.xml in the root of the eclipse project only.
Please help me to solve this problem
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
You've got a bunch of end parens ")" where you should have curly braces "}".

Also, your classpath syntax doesn't look right. Try :

<classpath path="${build.home}/lib"/>


Originally posted by saurav sarkar:



[/QB]
saurav sarkar
Ranch Hand

Joined: Jan 07, 2007
Posts: 180

Thanks Carol for your reply.
My build is successfull now......but the class files are
not generated under the bin folder.Please advise what to do here
saurav sarkar
Ranch Hand

Joined: Jan 07, 2007
Posts: 180

Dear All,

I have the build file like this



I am getting the error

BUILD FAILED
Target `bin' does not exist in this project.

Please help.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

How did you launch ant ? "ant bin" ? You must launch it using "ant all", to execute the target called "all".


[My Blog]
All roads lead to JavaRanch
Karthik Rajendiran
Ranch Hand

Joined: Aug 13, 2004
Posts: 211
I feel the case does matter
U have given Saurav but the actual directory is saurav


SCJP 1.4 SCWCD 1.4 SCDJWS 1.4
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3355

Another option to just to check,

  • What is the name of your build file?
  • If it is NOT the same as "build.xml", how do you invoke? Are you calling it as "ant -buildfile <Name_of_build_file.xml>" ?


  • Everything has got its own deadline including one's EGO!
    [CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
    saurav sarkar
    Ranch Hand

    Joined: Jan 07, 2007
    Posts: 180

    <project name="myproj" default="" basedir=".">


    <property name="build.home" value="${basedir}"/>



    <target name="compile" >
    <mkdir dir="${build.home}\bin"/>

    <javac srcdir="${build.home}"
    destdir="${build.home}\bin" >

    <classpath path="${build.home}\lib"/>
    </javac>
    </target>

    </project>

    This is the latest build file ....i have removed the target='all'
    But still i am getting the same error
    I am giving the build through Eclipse by setting up the Ant build for
    my project and rt clicking on the project and say build.

    Please help
    Christophe Verré
    Sheriff

    Joined: Nov 24, 2005
    Posts: 14688
        
      16

    If you leave the default target empty, it's not going to do anything, unless you explicitly tell which target you want to execute.
    I have tried to copy/paste your build.xml, and to execute under Eclipse. Nothing happens, but the build is successful :


    Then I have tried to explicitly set the target called "compile" to be executed. It is also successful :

    The "bin" directory has been created.

    I am giving the build through Eclipse by setting up the Ant build for my project

    Do you mean : Right click on your project -> Properties -> Builder -> Ant builder ?
    If so, please tell us more about your settings in it.
    [ September 04, 2007: Message edited by: Christophe Verre ]
    Raghavan Muthu
    Ranch Hand

    Joined: Apr 20, 2006
    Posts: 3355

    Yes, that is correct.

    Its better NOT to leave the 'default' attribute empty. can you please recheck your configuration as christophe asked and get back?
    saurav sarkar
    Ranch Hand

    Joined: Jan 07, 2007
    Posts: 180

    Thanks Christophe and Raghavan for the reply.

    here is my new build file after putting the compile
    as the default target



    the error coming is

    BUILD FAILED
    Target `bin' does not exist in this project.

    my settings in the eclipse for the Ant build

    buildfile: ${workspace_loc:/myproj/build.xml}

    Base Directory: C:\Saurav\myproj


    please help
    Christophe Verré
    Sheriff

    Joined: Nov 24, 2005
    Posts: 14688
        
      16

    Sorry, I'm puzzled. The error is "Target `bin' does not exist in this project. ", which means that you are trying to execute a target called "bin", which obviously does not exist. It might be something in your project setting. Did you check "Properties -> Builder" on your project ?
    [ September 04, 2007: Message edited by: Christophe Verre ]
    saurav sarkar
    Ranch Hand

    Joined: Jan 07, 2007
    Posts: 180

    Thanks Cristophe for your reply.
    I had a target set as bin in the properties.
    But now i am getting

    Unable to find a javac compiler;
    com.sun.tools.javac.Main is not on the classpath.
    Perhaps JAVA_HOME does not point to the JDK

    Though i have added tools.jar in the user entries of the classpath
    as well as the classpath mentioned in the build.xml

    Please help
    Raghavan Muthu
    Ranch Hand

    Joined: Apr 20, 2006
    Posts: 3355

    Can you please check your JAVA_HOME environment variable?

    It should point to the HOME direcotry where JDK is installed and not have "bin" attached with it.

    For example, if you have installed your JDK in C:\j2sdk1.4.2_12 directory, your JAVA_HOME should point to "Set JAVA_HOME=C:\j2sdk1.4.2_12" and NOT "Set JAVA_HOME=C:\j2sdk1.4.2_12\bin".
    saurav sarkar
    Ranch Hand

    Joined: Jan 07, 2007
    Posts: 180

    Thanks Raghavan for the reply.
    I have had the JAVA_HOME exactly as mentioned.

    But i am giving the build in Eclispe so i dont need the
    JAVA_HOME to be set in the Environment variables.

    Is there anything i need to do in the Eclipse?
     
     
    subject: Simple Ant Build