This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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.
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.