File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes IDEs, Version Control and other tools and the fly likes ClassPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "ClassPath" Watch "ClassPath" New topic
Author

ClassPath

Rufus BugleWeed
Ranch Hand

Joined: Feb 22, 2002
Posts: 1551
Seems as though when I was getting started using ANT/Eclipse I had a classpath problem. Does ANT in Eclipse use the classpath of the environment it runs under while Eclipse uses the buildpath to create the targets?
The question that showed up from my user is
I have an Ant build.xml file that has a target, which is the default target. When I run the Ant build from the shell, the process goes smoothly and the JUnit test succeeds.
However, when I run the Ant build from inside Eclipse, I get ClassDefNotFoundErrors for javax.rmi.PortableRemoteObject.
Running the Ant build with -verbose setting, I see that the classpath being used is (linebreaks added for readability):
"Using CLASSPATH
D:\data\Software Development\eclipse\ContactMgt\build\classes;
D:\swdev\java\j2se\jdk1.3.1_02\jre\lib\rt.jar;
D:\swdev\java\j2sdkee1.3.1\lib\j2ee.jar;
D:\swdev\JBoss\jboss-3.2.1_tomcat-4.1.24\client\jbossall-client.jar;
D:\swdev\java\jUnit\junit3.8.1\junit.jar;
D:\swdev\ApacheGroup\Log4J\jakarta-log4j-1.2.8\dist\lib\log4j-1.2.8.jar;
D:\swdev\eclipse\plugins\org.apache.ant_1.5.1\ant.jar;
D:\swdev\eclipse\plugins\org.apache.ant_1.5.1\optional.jar"
On inspection, I found that rt.jar contains the javax.rmi.PortableRemoteObject, and rt.jar IS on the classpath.
So in short, the same build script works fine with Ant from the command line, but not with Ant within Eclipse.
Anyone have any ideas?

We eventually got the system to work but we're not sure what we did to fix it.
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
You can get some strange compile issues from within Eclipse if you don't set the compiler to match the default eclipse compiler. Try adding this to your build.xml and setting it as a dependency on your compile step...


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Ed Burnette
Author
Ranch Hand

Joined: Jun 10, 2003
Posts: 142
Originally posted by Rufus BugleWeed:
Does ANT in Eclipse use the classpath of the environment it runs under while Eclipse uses the buildpath to create the targets?

First of all running Ant in Eclipse uses the same JVM that Eclipse is using. There's a new option to start up a new JVM for Ant in the 3.0 version but it's off by default because using the existing one is faster.
Next, Ant or anything else running under Eclipse doesn't use the CLASSPATH environment variable. CLASSPATH is the root of all evil so this is ok with me, but it suprises many new users. To get something on Ant's classpath, use Window > Preferences > Ant > Runtime.


Ed Burnette, Author of Hello Android
Blog: ZDNet's Dev Connection - Twitter: @eburnette
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassPath