Compiling Java in Windows Command Prompt

I have downloaded a Java program that needs to be compiled before it can be run. However the compilation hasn’t gone smoothly, and lots of ClassDefFound errors are being produced.

I am having trouble finding the cause of this, because I can’t read the errors that occur during compilation due to the limitations of the command prompt. Is there a way of printing all of the output of the javac program to a file so I can read through it and try and trace the cause of the problems?

Have you tried redirecting the output to a file, e.g. javac whatever > file.txt ?

I tried that: the files were created but they are empty–the verbose output did not get written to the file it seems.


javac 2> out.txt

The “2>” causes STDERR to get piped to the file.

Track down what classes it says are missing, then figure out which jar files contain those classes. My hunch is that some jar files are missing from your classpath.

Before you run javac, specify your classpath like this. Add as many jar files as you need, separated by semicolons:
set classpath=.;c:\jdk1.3\lib\

Another good GUI (in fact, a complete Java IDE) is Eclipse

As for your specific problem – the files you created, as noted above, because you have only been redirecting STDOUT to the file. You need to redirect STDERR as well – I almost certain the “2>” syntax doesn’t work on Windows cmd prompt, but I’m sure a quick browse of the help manuals should tell you what the correct syntax is.

And your basic problem is that you haven’t set up your CLASSPATH. you can either supply it as part of the command (“javac -classpath xxxx …”) or set the %CLASSPATH% envvar and save yourself some typing.

Good luck!


So little confidence…you should have given it a try before guessing that it wouldn’t work. This syntax does indeed work.

Before I posted it, I tested this very command on my Windows 2000 command prompt with a short Java program bearing an intentional bug, and I demonstrated the OP’s problem, followed by the correct behavior. So, to be clear, I wasn’t guessing when I posted it; I was certain.

Huh. You’re right. I did try it yesterday, before writing, and it didn’t work for me – probably I had a type on my command line or something.

Anyway, sorry sbout that (both to the OP for the misinformation and to minor7flat5 for the lack of confidence) :frowning:

OK, I’m back.

The 2> did work to get the error output to print to file–unfortunately it did not shed much light on the problem.

The program I’m having trouble with is ‘openjgraph’, an old sourceforge graphing package that is required to be installed for a more sophisticated program to run. I have followed the installation procedure decribed in the README file several times, and played about with the classpath in the setenv batch file, but some classes just don’t seem to be being installed. This is enough for the program not to compile.

Hmmm… is the software you’re installing (openjgraph, which I know nothing about) old enough to describe itself as, say, “Java 1.2 compatible”? Because, if so, you may be running into back-compatability issues between your JRE (which I’ll wager is probably Java 1.4 based, or at least Java 1.3) and the software.

If this is the case, I can’t help you without seeing it for myself (in other words, not at all…) – but if this is the only Java app you’re using, you could try grabbing an onld (1.2-based) JRE and installing on top of that. You could probably install multiple JRE’s as well, but then keeping track of which one each of your apps is using becomes a real PITA.



My JRE is 1.5, but the software was developed based on 1.3. I did begin to suspect it might be something like this, but I had expected these things to be backwards compatible. Is this not the case in Java?

If this is the problem, where can I get a 1.3 JRE from?

I’m pretty sure the 1.4 JRE is back-compatible to run 1.3 apps. And it should still be freely available at Sun’s website – where you should probably be able to find all other kinds of compatability issues, as well –

For back-compatabiliy issues, this page is probably a good starting point.


Hi bluecanary, I just downloaded this fine application, compiled it, and ran it. Here’s what happened:

  1. They say that it includes binaries; that’s hogwash. There’s no precompiled binary in their zip file other than libraries such as Ant and Log4J.
  2. I had to fiddle with setEnv.bat in order for things to work (and, indeed, it told me so when I tried to run one of the examples).
  3. Use compileall.bat to do the build.
  4. I ran under jdk1.4.2_05
  5. The app looks cool, if directed graphs are your thing.
  6. Their application uses several external libraries, so this is most likely where your classpath problems are coming.

These are the libraries you need to be concerned with:

It may very well turn out that you don’t really need all of those either.
In fact, I ran example 1 as such:

set CLASSPATH=.;dist\openjgraph.jar;dist\log4j-core.jar
java -classpath %CLASSPATH% examples.SameGraph

I only needed two of the jars for it to run. Log4J complained because it couldn’t find its init file (harmless). I’m sure that if I had tried some of the serialization features, it would have complained about not finding the XML stuff.

Why don’t you post a couple of the NoClassDefFoundError lines?

(Hey, Noone Special, no harm done :))