aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Set Ant Classpath for Compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Set Ant Classpath for Compile" Watch "Set Ant Classpath for Compile" New topic
Author

Set Ant Classpath for Compile

Lou Pelagalli
Ranch Hand

Joined: Nov 11, 2003
Posts: 150
    
    1
Hi,

If I have my classpath Windows XP environment variable defined, in this case .;C:\Sun\AppServer\lib\javaee.jar;C:\Java\lib\mysql.jar;, is it still necessary to define the classpath in the build.xml for Ant?

If yes can you help me convert the classpath shown above to what Ant requires?

Code and Ant output below.

Thanks,

Lou

File build.properties


File build.xml


Ant output
Lou Pelagalli
Ranch Hand

Joined: Nov 11, 2003
Posts: 150
    
    1
I got it.

First in your buld.properties file
Lou.classpath=C:/Sun/AppServer/lib/javaee.jar;C:/Java/lib/mysql.jar

Second in your build.xml file
<path id="classpath.base">
<pathelement path="${Lou.classpath}"/>
</path>

Then add to your compile target in build.xml
<classpath refid="classpath.base"/>
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

If I have my classpath Windows XP environment variable defined, in this case .;C:\Sun\AppServer\lib\javaee.jar;C:\Java\lib\mysql.jar;,

Just an side, but setting the CLASSPATH env var globally is a very bad idea. At some point some Java code will break and you will spend countless hours tracking down the issue only to find out that is was because you set CLASSPATH globally and the Java app was therefore picking up the wrong classes.

JBoss In Action
Lou Pelagalli
Ranch Hand

Joined: Nov 11, 2003
Posts: 150
    
    1
Peter Johnson wrote:
Just an side, but setting the CLASSPATH env var globally is a very bad idea. At some point some Java code will break and you will spend countless hours tracking down the issue only to find out that is was because you set CLASSPATH globally and the Java app was therefore picking up the wrong classes.


Thank you for the information Peter, and for saving me countless future hours. I have removed the classpath from my environment variables.

I have been wondering, and perhaps you could answer, how to deploy and use my war and jar files.

I'm working on a Tomcat application.

Would it be best to deploy my jar files for db connections to $CATALINA_HOME\lib and then use $CATALINA_HOME\lib for my classpath, or some other configuration?

Thank you for your time.

Lou
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

Usually it is best to place your JAR files in WEB-INF/lib in your WAR file.
Lou Pelagalli
Ranch Hand

Joined: Nov 11, 2003
Posts: 150
    
    1
I see Peter, thank you!

I think adding a lib folder to my eclipse workspace and keeping my jar files there would be a good centralized place for them.

The eclipse project would then use the jar files, and then I have a good reference for building my war files.

Trying to keep things nice and neat, and organized, ... and simple.

Thank You for your time Peter!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

Have you looked at Maven? It is very good at organizing and maintaining JAR files, and it removes the need to clutter up your Eclipse projects with lib directories containing JAR files. Especially handy if you have multiple projects and they all use very similar sets of JARs.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set Ant Classpath for Compile