• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

an ant question

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I apologise if ant is not appropriate for this forum, but to pleadimy case, I already tried on the nabble ant forum and didn't get an answer, and ant is used almost exclusively for java.


I am trying to run this example :

http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html


I get this error:


$ ant
Buildfile: C:\javaplay\log\src\oata\build.xml

BUILD FAILED
Target "jar" does not exist in the project "HelloWorld". It is used from target "run".

Total time: 0 seconds





Things ran ok till I got to the point of adding log4j
and changed the build.xml here:

according to directions:




direct struct:

oata:

HelloWorld.java
build.xml

build/classes/oata
HelloWOrld.class

build/jar:
HelloWorld.jar

lib :
log4j.jar

src
...
build.xml



[Edit: put code between [code] and [/code] ubb code blocks]
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error is saying that you have a target called "run" that depends on a target called "jar", but you don't have a target called "jar" in the build file. Now, I do see that you have a run target that depends on jar. I also see that you have a jar target, but it seems like that might be in a different build file. Actually, it's a bit hard to parse your example code. In the future, please use code tags to make your code more readable.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apart from the fact that the classpath reference is missing, did you save your file ?
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  • The first bit of the ant build file you posted does not have a "jar" target between the "compile" target and the "run" target.
  • The second ant build file does have it.


  • I am wondering whether Greg is correct - do you have 2 build.xml files? It appears from your posted "direct struct" that you have one build.xml file in the oata directory and another in the src directory. There should only be one build.xml file, and it should be in the base directory, not in the oata or the src directory.

    To make that a little clearer (I hope), here is the directory structure I created in order to replicate the tutorial's example:


    Christophe also mentions a missing classpath issue: search in the tutorial for "lib.dir" - it only occurs in 2 locations, both of which are missing in your build file.
     
    Brian R Wolf
    Greenhorn
    Posts: 18
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    First let me say Java Ranch is an amazing site. To wake up and finding three masters providing their opinions to my problem is almost unheard of going far beyond helping us code to preserving our well being and sanity in an often lonely and difficult job.

    I got it all to work after starting all over again. Now, onward, and thanks again. (and yes I will use proper formatting next time)

     
    Brian R Wolf
    Greenhorn
    Posts: 18
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It does seem ant files are non-trivial and require some work and study, I was hoping to get one more clarification...
    regarding this part of the tutorial...






    they reference this part of the build.xml in this statement:

    In this example we start our application not via its Main-Class manifest-attribute, because we could not provide a jarname and a classpath.



    I don't really know what they mean here, why can't you provide jarname and classpath, and what does it have to do with the Main-Class attribute? Why did things change so much when we added log4j in terms of simply running the program?




     
    Greg Charles
    Sheriff
    Posts: 3063
    12
    Mac IntelliJ IDE Python VI Editor Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Congratulations on getting that example working! Yes, sometimes it's best to start from scratch, rather than trying to debug an intractable problem.

    For your new query, I think you've run across a general problem of computer books. Good tech people are often not good writers. There are exceptions, many of whom are sheriffs and founders on this site. I don't know about the author of your book, but the sentence you quote is a bit tortured. I'm interpreting it the way you do, that somehow you can't provide both a jar file and a classpath to Ant java task. If that's what it means, then I'm pretty sure it's just wrong. You could confirm that by trying to put in a jar file and a classpath and seeing if it works.

    I can at least tell you that the "main class" manifest-attribute that it mentions is an entry in the jar's MANIFEST.MF file, which gives the jar a default class to run. That allows you to run the jar as:

    java -jar myjar.jar

    Or even launch it with a double-click on Windows and some other OSs if you set up file associations right.

    Again it seems to be saying that you can't do that from the java task now that you need to specify a classpath too, and as far as I know that's just not right.
     
    Don't touch me. And dont' touch this tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic