I'm trying to compile and run this on WINnt
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
public class Hello {
static Logger logger = Logger.getLogger(Hello.class);
public static void main(String argv[]) {
BasicConfigurator.configure();
logger.debug("Hello world.");
logger.info("What a beautiful day.");
}
}
I have placed my log4j-1.2.9.jar file in
E:\jakarta-log4j-1.2.9\dist\lib\
I have set my CLASSPATH (in ControlPanel>System>Environment>System
Variables) to include
;E:\jakarta-log4j-1.2.9\dist\lib\log4j-1.2.9.jar
The result is
E:\AAAtest>javac Hello.java
Hello.java:1: package org.apache.log4j does not exist
import org.apache.log4j.Logger;
Hello.java:2: package org.apache.log4j does not exist
import org.apache.log4j.BasicConfigurator;
Hello.java:6: cannot resolve symbol
symbol : class Logger
location: class Hello
static Logger logger = Logger.getLogger(Hello.class);
Hello.java:6: cannot resolve symbol
symbol : variable Logger
location: class Hello
static Logger logger = Logger.getLogger(Hello.class);
Hello.java:11: cannot resolve symbol
symbol : variable BasicConfigurator
location: class Hello
BasicConfigurator.configure();
^
5 errors
I can compile the file using the command line
E:\AAAtest>javac -classpath
E:\jakarta-log4j-1.2.9\dist\lib\log4j-1.2.9.jar Hell
o.java
but it won't run this way
E:\AAAtest>java Hello
Exception in thread "main" java.lang.NoClassDefFoundError: Hello
or this
E:\AAAtest>java -classpath
E:\jakarta-log4j-1.2.9\dist\lib\log4j-1.2.9.jar Hello
Exception in thread "main" java.lang.NoClassDefFoundError: Hello
Regards
CCJ
end the line with ; close the cmd prompt and re-open to compile.
"CCJ" <ccjo...@yahoo.co.uk> wrote in message
news:850aa21f.04111...@posting.google.com...
| chander <sa...@ziksa.net> wrote in message
news:<lLhkd.17731$Z7.6...@news20.bellglobal.com>...
| > CCJ wrote:
<snip>
|
| Thanks Chander. I modified the CLASSPATH as I think you suggested.
| Unfortunately there seems to be no difference
| Regards
| CCJ
Hi,
in your DOS window type set & then hit return. Check the classpath entry to
see if your classpath is set up correctly.
It really is much, much, much easier to compile, build & run your projects
using Ant http://ant.apache.org/ . It doesn't take long to get up & going
with Ant (less than an hour) & it will save you loads of headaches like this
in the future.
Here's a sample Ant build.xml file with a compile target to get you started,
modify it to your needs. Using the Ant documentation, it shouldn't take you
long to work out how to write a target to run your code (check out the java
task!) & you can use the same classpath you used to compile.
HTH
<?xml version="1.0" encoding="iso-8859-1"?>
<project name="test" default="compile">
<property name="source.root" value="src"/>
<property name="class.root" value="classes"/>
<property name="lib.dir" value="..\lib"/>
<property name="j2ee.jar" value="D:\j2sdkee1.3.1\lib\j2ee.jar"/>
<path id="project.class.path">
<pathelement location="${class.root}"/>
<pathelement location="${j2ee.jar}"/>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>
<target name="compile">
<javac srcdir="${source.root}"
destdir="${class.root}"
debug="on"
deprecation="on"
source="1.4">
<classpath refid="project.class.path"/>
</javac>
</target>
</project>
--
-P
"Programs that are hard to read are hard to modify.
Programs that have duplicated logic are hard to modify.
Programs with complex conditional logic are hard to modify"
( Kent Beck)
It took a few hours but a liberating experience I was able to compile,
jar and run in one hit!
Thanks once again for the fishing lesson.
Regards
CCJ
The drive letter isn't required if the ant build.xml file is on the same
drive. I also always use forward slashes (../lib). That way the build will
work both on windows or unix.
The jakarta projects can also provide some good examples of how to put
together an ant build.xml file. The use of a build.properties include file
will prove especially useful for larger projects.