wood burning stoves 2.0*
The moose likes IDEs, Version Control and other tools and the fly likes Ant's classpath vs Eclipse's classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Ant Watch "Ant New topic
Author

Ant's classpath vs Eclipse's classpath

Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Fellows:
I have started using eclipse this week and I'm having problems with compilations.
The project that I'm working on is quite big, it has predefined build.xml files with .properties files that declares the libraries needed for the classpath.
In eclipse, I added in my classpath all the libraries I needed to compile my code (in the same order that build.xml declares it). But, when I compile my code I get errors, complaining that a class is not defined in the classpath.
If I go to my command prompt and execute the same target, the program compiles with no problems.
Having exactly the same libraries in my classpath, I do not know what the problem might be. I have read this post and this one. On these posts, a suggestion is add this to build.xml

I have not tried this snippet (will do it tomorrow), but I'd also love not to touch build.xml at all (policies around here,specially when I'm the only one using eclipse). Is there any other workaround for this problem?


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
What do you mean by "I added in my classpath all the libraries" - exactly which classpath are you speaking of? And how do you compile your code inside eclipse - using Ant, using the Eclipse compiler, or something else?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Originally posted by Ilja Preuss:
What do you mean by "I added in my classpath all the libraries" - exactly which classpath are you speaking of? And how do you compile your code inside eclipse - using Ant, using the Eclipse compiler, or something else?

My code needs a specific set of libraries to compile. I added those libraries to the classpath in eclipse.
I do not want to use eclipse for that. I want to use Ant (which is integrated in eclipse) for compilation purposes. What I'm saying is that compilation is successful when compiling my code using the same build.xml, with the same libraries in the command prompt. But if I use the IDE, it throws errors.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Andres Gonzalez:
My code needs a specific set of libraries to compile. I added those libraries to the classpath in eclipse.

And I don't understand what you mean by this, sorry. How did you do it?

I do not want to use eclipse for that. I want to use Ant (which is integrated in eclipse) for compilation purposes. What I'm saying is that compilation is successful when compiling my code using the same build.xml, with the same libraries in the command prompt. But if I use the IDE, it throws errors.

What errors do you get? Can you show us the relevant parts of the build script?
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Thank you Ilja -
In build.xml you can specify properties. I have a properties called {libraries} that points to jar files that are needed in order to compile the code successfully. This is a post I submitted in the eclipse mailing list:

(Notice the classpath pointing to my {libraries} properties)
Using this target in the command prompt results in *successful* compilation.
However, if I try running the the same task inside eclipse, it throws
a compiler error, something like:
"This compilation unit indirectly references the missing type
javax.transaction.SystemException (typically some required class file is
referencing a type outside the classpath)"
I have added the *same* libraries that I have in my {libraries} into
eclipse's classpath, as well as the ant runtime classpath (in the same
order as well), but I can't get this to work. I have also checked where SystemException file is located and is indeed in one of the jar files that I have in the classpath

</blockquote>
hope it's now clear, this is so frustrating
[ October 28, 2003: Message edited by: Andres Gonzalez ]
[ October 28, 2003: Message edited by: Andres Gonzalez ]
[ October 28, 2003: Message edited by: Andres Gonzalez ]
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
As you can see, I have tried many ways posting the target, but javaranch doesn't like it anyway, even if I put it inside a code block, a quote code, etc.. it is something like this
javac srcdir="${src}" destdir="${build}" classpath="${libraries}"
[ October 28, 2003: Message edited by: Andres Gonzalez ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I see. Does your classpath in ${libraries} include *relative* paths?
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Originally posted by Ilja Preuss:
I see. Does your classpath in ${libraries} include *relative* paths?

hmm .. good point... they're declared like this:
property name="libraries" value="../lib/common/myFirst.jar;../lib/mySecond.zip;.....
BTW, my directory structure is :
D:\source\myProject\src
D:\source\myProject\lib
..
..
build.xml is located on myProject folder. So, in command line, i position myself in d:\source\myProject and use ant targets with no problems.
my base dir in build.xml is : basedir="."
In eclipse, when I right click on my project to see the properties, this is what I get:
path: /myProject
Location: d:\source\myProject
hmm that might be the reason, shouldn't the path be /source/myProject?
thanks again
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
hmm .. that couldn't be the problem... otherwise the whole code wouldn't compile. It's just this single class that is breaking everything off, even though it's in the classpath.
Another suggestion from the eclipse forum *itself* was to use ant outside eclipse, specially when the project is big (my case).
I miss intelij
 
jQuery in Action, 2nd edition
 
subject: Ant's classpath vs Eclipse's classpath
 
Similar Threads
Eclipse and CLASSPATH
how to include jar files in classpath (eclipse +Quartz Scheduler)
Ant xml script & javac + JAVA_HOME classpath
Eclipse 3.1 and jsp
ANT: Problems with imported libraries