Genadinik
Genadinik

Reputation: 18629

Ant Javac and Commandline Javac give different results

I have a class that imports some servlet libraries. When I compile it from command-line it is fine.

When I use the ant compile task to compile it, it gives the errors that it can't find the servlet libraries in its path.

Is that a known/common occurrence?

Here is my Ant target:

<target name="compile" depends="prepare" description="compile the source" >
    <echo>=== COMPILE === SRCDIR: ${src}/com/udfr/src/java </echo> <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}/com/udfr/src/java" destdir="${dist}/WEB-INF/classes"/>
</target>

Upvotes: 1

Views: 873

Answers (3)

Heisenbug
Heisenbug

Reputation: 454

Difference is because ANT's javac has debug mode as false by default.

Turning

debug="true"

in javac of ANT script will generate the same class file which is generated with maven or normal javac in cmd.

Upvotes: 0

Laurent Pireyn
Laurent Pireyn

Reputation: 6865

For some reason, the JAR file containing the Servlet API is part of your classpath when you compile your program in command line. However, it's not in the classpath of the javac Ant task.

You should explicitely add the JAR file to the classpath in your javac Ant task. There are several ways to do that; please read http://ant.apache.org/manual/Tasks/javac.html

Upvotes: 2

Jon Skeet
Jon Skeet

Reputation: 1499770

It's a common occurrence if you don't specify the servlet libraries properly in the classpath for the javac task... I suspect that's the problem. If you post the task which fails and the command line which works, we'll be able to help more.

Upvotes: 2

Related Questions