• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Piet Souris

Trouble understanding Ant('s classpath)

Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have an Eclipse project that makes use of Hibernate and Log4j. The project has a lib folder where all the necessary jars reside. The project's build script makes use of Hibernate Tools to generate the java files and the db scheme. Apart from that, the build script declares a classpath which consists of the lib dir. Now when running Eclipse I get NoClassDefFoundExceptions unless I explicitly configure Eclipse's Ant plugin to include the jars from the project's lib folder. For me this looks as if I include them twice: in the script and in the Ant configuration. Is that correct or do I miss something?

Saloon Keeper
Posts: 21708
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I can't quite wrap my poor tired brain around your question, so I'll give an answer and see if you can work back from there. Sorry about that, but I'm out sick today.

Basically, Ant hasn't got any particular magic connection to Eclipse. The ant support plugin is part of the standard package (or at least the Java one, which is what most of us care about). However, this is more of an assist than a tight connection.

What that means in practical terms is that when you run Ant inside Eclipse, what you'll get should be identical to what you get running Ant on the same build.xml file when Eclipse isn't running at all. Most notably, Eclipse project classpaths don't get a free ride into Ant. You either have to define the project classpath inside the build.xml or you have to define the project classpath on the Ant setup dialog.

I recommend doing it inside the build.xml because that makes it "real" and more importantly, write-once, run-anywhere (to steal a phrase). If you define the classpath on the Ant dialog, you're achieving the same net effect as you'd get by manually setting the CLASSPATH environment variable before calling Ant. If you explicitly define the classpath in the build.xml, people don't need this kind of secret external knowledge, so they might not hunt you down and kill you when years later someone needs to recompile in the middle of the night and it won't compile.

Just for info, I wrote an XSL a while back that will take an Eclipse project file and spit out a prototype Ant script with javac steps and classpaths. I may have posted a copy of it either in this forum or in the XML forum.

Unless you've got a really long and ugly classpath setup, you're better off doing things manually, however.
What I don't understand is how they changed the earth's orbit to fit the metric calendar. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!