You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by NR031 <na...@cognizant.com> on 2009/03/30 12:01:49 UTC

Class-Path error in Ant Script

Hi,


   I am writing my Ant build script according to the tutorial given 
http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html here . I have
downloaded the Log4j from the site
http://www.apache.org/dist/logging/log4j/1.2.14/logging-log4j-1.2.14.zip. I
have copied the JAR file to my local directory
(D:\178010\AntScripts\Projects\lib).

  I have created a java file in the path
D:\178010\AntScripts\Projects\src\cts\HelloWorld.java

package abc;
import org.apache.log4j.Logger;
 import org.apache.log4j.BasicConfigurator; 
public class HelloWorld
 {
 static Logger logger = Logger.getLogger(HelloWorld.class); 
public static void main(String[] args) 
{ 
BasicConfigurator.configure();
 logger.info("Hello World"); // the old SysO-statement
 }
 }

and my build file is like this :

<u>build.xml</u>:
<project name="HelloWorld" basedir="D:\178010\AntScripts\Projects"
default="main">
<property name="src.dir"     value="src"/>
    <property name="build.dir"   value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="jar.dir"     value="${build.dir}/jar"/>
    <property name="main-class"  value="abc.HelloWorld"/>
    <property name="lib.dir"     value="lib"/>
    <path id="classpath">
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>
<target name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
    </target>
<target name="jar" depends="compile">
        <mkdir dir="${jar.dir}"/>
        <jar destfile="${jar.dir}/${ant.project.name}.jar"
basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
            </manifest>
        </jar>
    </target>
   
     <target name="run" depends="jar">
        <java fork="true" classname="${main-class}">
            <classpath>
                <path refid="classpath"/>
                <path location="${basedir}/jar/HelloWorld.jar"/>
            </classpath>
        </java>
    </target>
</project>

when I run the target "run" I am getting :

    [javac] D:\178010\AntScripts\Projects\src\cts\HelloWorld.java:13:
package or
g.apache.log4j does not exist
    [javac] import org.apache.log4j.Logger;
    [javac]                        ^
    [javac] D:\178010\AntScripts\Projects\src\cts\HelloWorld.java:14:
package or
g.apache.log4j does not exist
    [javac]  import org.apache.log4j.BasicConfigurator;
    [javac]                         ^
    [javac] D:\178010\AntScripts\Projects\src\cts\HelloWorld.java:17: cannot
fin
d symbol
    [javac] symbol  : class Logger
    [javac] location: class cts.HelloWorld
    [javac]  static Logger logger = Logger.getLogger(HelloWorld.class);
    [javac]         ^
    [javac] D:\178010\AntScripts\Projects\src\cts\HelloWorld.java:17: cannot
fin
d symbol
    [javac] symbol  : variable Logger
    [javac] location: class cts.HelloWorld
    [javac]  static Logger logger = Logger.getLogger(HelloWorld.class);
    [javac]                         ^
    [javac] D:\178010\AntScripts\Projects\src\cts\HelloWorld.java:20: cannot
fin
d symbol
    [javac] symbol  : variable BasicConfigurator
    [javac] location: class cts.HelloWorld
    [javac] BasicConfigurator.configure();
    [javac] ^
    [javac] 5 errors

BUILD FAILED
D:\178010\AntScripts\Projects\build.xml:17: Compile failed; see the compiler
err
or output for details.

Total time: 1 second

What is wrong in the above code?


Thanks in advance,

-- 
View this message in context: http://www.nabble.com/Class-Path-error-in-Ant-Script-tp22779845p22779845.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: ****SPAM**** Class-Path error in Ant Script

Posted by "Knuplesch, Juergen" <Ju...@icongmbh.de>.
You need log4j.jar in the compile-classpath 


-- 
Jürgen Knuplesch                    
-----Ursprüngliche Nachricht-----
Von: NR031 [mailto:nataraja.cp@cognizant.com] 
Gesendet: Montag, 30. März 2009 12:02
An: user@ant.apache.org
Betreff: ****SPAM**** Class-Path error in Ant Script


Hi,


   I am writing my Ant build script according to the tutorial given http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html here . I have downloaded the Log4j from the site http://www.apache.org/dist/logging/log4j/1.2.14/logging-log4j-1.2.14.zip. I have copied the JAR file to my local directory (D:\178010\AntScripts\Projects\lib).

  I have created a java file in the path D:\178010\AntScripts\Projects\src\cts\HelloWorld.java

package abc;
import org.apache.log4j.Logger;
 import org.apache.log4j.BasicConfigurator;
public class HelloWorld
 {
 static Logger logger = Logger.getLogger(HelloWorld.class);
public static void main(String[] args)
{
BasicConfigurator.configure();
 logger.info("Hello World"); // the old SysO-statement  }  }

and my build file is like this :

<u>build.xml</u>:
<project name="HelloWorld" basedir="D:\178010\AntScripts\Projects"
default="main">
<property name="src.dir"     value="src"/>
    <property name="build.dir"   value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="jar.dir"     value="${build.dir}/jar"/>
    <property name="main-class"  value="abc.HelloWorld"/>
    <property name="lib.dir"     value="lib"/>
    <path id="classpath">
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>
<target name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
    </target>
<target name="jar" depends="compile">
        <mkdir dir="${jar.dir}"/>
        <jar destfile="${jar.dir}/${ant.project.name}.jar"
basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
            </manifest>
        </jar>
    </target>
   
     <target name="run" depends="jar">
        <java fork="true" classname="${main-class}">
            <classpath>
                <path refid="classpath"/>
                <path location="${basedir}/jar/HelloWorld.jar"/>
            </classpath>
        </java>
    </target>
</project>

when I run the target "run" I am getting :

    [javac] D:\178010\AntScripts\Projects\src\cts\HelloWorld.java:13:
package or
g.apache.log4j does not exist
    [javac] import org.apache.log4j.Logger;
    [javac]                        ^
    [javac] D:\178010\AntScripts\Projects\src\cts\HelloWorld.java:14:
package or
g.apache.log4j does not exist
    [javac]  import org.apache.log4j.BasicConfigurator;
    [javac]                         ^
    [javac] D:\178010\AntScripts\Projects\src\cts\HelloWorld.java:17: cannot fin d symbol
    [javac] symbol  : class Logger
    [javac] location: class cts.HelloWorld
    [javac]  static Logger logger = Logger.getLogger(HelloWorld.class);
    [javac]         ^
    [javac] D:\178010\AntScripts\Projects\src\cts\HelloWorld.java:17: cannot fin d symbol
    [javac] symbol  : variable Logger
    [javac] location: class cts.HelloWorld
    [javac]  static Logger logger = Logger.getLogger(HelloWorld.class);
    [javac]                         ^
    [javac] D:\178010\AntScripts\Projects\src\cts\HelloWorld.java:20: cannot fin d symbol
    [javac] symbol  : variable BasicConfigurator
    [javac] location: class cts.HelloWorld
    [javac] BasicConfigurator.configure();
    [javac] ^
    [javac] 5 errors

BUILD FAILED
D:\178010\AntScripts\Projects\build.xml:17: Compile failed; see the compiler err or output for details.

Total time: 1 second

What is wrong in the above code?


Thanks in advance,

--
View this message in context: http://www.nabble.com/Class-Path-error-in-Ant-Script-tp22779845p22779845.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org