aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Not able to compile java files with Ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Not able to compile java files with Ant" Watch "Not able to compile java files with Ant" New topic
Author

Not able to compile java files with Ant

Deb Boyles
Greenhorn

Joined: Aug 05, 2004
Posts: 1
Hi, I have been trying to resolve this problem for over a week now and I'm really hoping someone here will be able to help me.

I am working on a automated build/deploy application. This application extracts code from cvs for the main project and dependent projects. The dependent projects need to be compiled and made into jars. This issue I am having is in the ant <javac> command. When the command is called, the java files are found but errors get thrown because all of the dependent packages/imports are not being seen.

I have added absolute paths to those packages but errors are still thrown. For instance here is my <javac> code:

<target name="compileJavaJar" >
<echo message="compiling LMIG_logging" />
<javac srcdir="${src.dir}" destdir="${outputDir}"
classpath="C:/workspace/ReferenceBuildProcess/extract/LMIG_logging/lib/commons-logging.jar, C:/workspace/ReferenceBuildProcess/extract/LMIG_logging/lib/log4j-1.2.8.jar,
C:/workspace/ReferenceBuildProcess/extract/LMIG_logging/lib/xml-apis.jar
C:/workspace/ReferenceBuildProcess/extract/LMIG_logging/lib/commons-logging-api.jar" >
</javac>
</target>

compileJavaJar:
[echo] compiling LMIG_logging
[javac] Compiling 1 source file to C:\workspace\ReferenceBuildProcess\extract\LMIG_logging\src\com\lmig\common\logging
[javac] C:\workspace\ReferenceBuildProcess\extract\LMIG_logging\src\com\lmig\common\logging\LogFactory.java:8: cannot resolve symbol
[javac] symbol : class DOMConfigurator
[javac] location: package xml
[javac] import org.apache.log4j.xml.DOMConfigurator;
[javac] ^
[javac] C:\workspace\ReferenceBuildProcess\extract\LMIG_logging\src\com\lmig\common\logging\LogFactory.java:29: cannot resolve symbol
[javac] symbol : variable DOMConfigurator
[javac] location: class com.lmig.common.logging.LogFactory
[javac] DOMConfigurator.configureAndWatch("/properties/log4j.xml");
[javac] ^
[javac] 2 errors

Here's my problem: The import statement that it's looking for is located within log4j-1.2.8.jar but it's not seeing it to allow the file to compile, is there any reason why this could happen? What do I need to do to resolve this? I'm assuming that it is a classpath issue but I've run out of ideas. There are other projects that I'm trying to work on as well and they don't recognize anything on their classpaths.

Any help at all would be very much appreciated.
No�l Verdurmen
Ranch Hand

Joined: Jul 28, 2004
Posts: 33
Hi Deb

I have just done a similar thing and that worked fine for me.

You seem to be using a package of apache. You probably did not include that in one of the jars (correct me if i am wrong. Make sure you include that on the classpath as well.

If that is not it, here are two more things to check:

Are you sure, that at the moment you start compiling, the bytecode of log4j-1.2.8.jar is in the specified path? (i.e., in C:/workspace/ReferenceBuildProcess/extract/LMIG_logging/lib/ )

If you compile your code direct from the cvs code, you have to be aware that the order in which you compile is important. (you should then compile log4j-1.2.8.jar before commons-logging.jar)

Good luck !


No�l
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The problem might also be in how you list the classpath elements in
<target name="compileJavaJar" >
<echo message="compiling LMIG_logging" />
<javac srcdir="${src.dir}" destdir="${outputDir}"
classpath="C:/workspace/ReferenceBuildProcess/extract/LMIG_logging/lib/commons-logging.jar, C:/workspace/ReferenceBuildProcess/extract/LMIG_logging/lib/log4j-1.2.8.jar,
C:/workspace/ReferenceBuildProcess/extract/LMIG_logging/lib/xml-apis.jar
C:/workspace/ReferenceBuildProcess/extract/LMIG_logging/lib/commons-logging-api.jar" >

I believe Ant expects ";" or ":" as the path separator, not "," as you have here.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

You'd be better off using an embedded <classpath> element with <fileset> elements, as opposed to the classpath attribute. It gives you more flexibility, and is less prone to delimiter errors.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Consider Paul's rocket mass heater.
 
subject: Not able to compile java files with Ant