# Compiling Java in Windows Command Prompt

**URL:** <https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340>\
**Category:** Factual Questions\
**Created:** [June 29, 2005, 10:31am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340 "2005-06-29T10:31:30Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluecanary](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bluecanary/32/3614_2.png) [@bluecanary](https://boards.straightdope.com/u/bluecanary)\
**Post date:** [June 29, 2005, 10:31am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/1 "2005-06-29T10:31:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Ximenean](https://avatars.discourse-cdn.com/v4/letter/x/aca169/32.png) [@Ximenean](https://boards.straightdope.com/u/Ximenean)\
**Post date:** [June 29, 2005, 10:34am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/2 "2005-06-29T10:34:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bluecanary](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bluecanary/32/3614_2.png) [@bluecanary](https://boards.straightdope.com/u/bluecanary)\
**Post date:** [June 29, 2005, 10:42am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/3 "2005-06-29T10:42:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![minor7flat5](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minor7flat5/32/258_2.png) [@minor7flat5](https://boards.straightdope.com/u/minor7flat5)\
**Post date:** [June 29, 2005, 11:05am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/4 "2005-06-29T11:05:09Z")

</div>

> [@Usram](#):
>
> Have you tried redirecting the output to a file, e.g. **javac _whatever_ \> file.txt**?

Almost…

```auto

javac Myfile.java 2> out.txt

```

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

---

<div class="post-metadata">

**Author:** ![ratatoskK](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ratatoskk/32/2987_2.png) [@ratatoskK](https://boards.straightdope.com/u/ratatoskK)\
**Post date:** [June 29, 2005, 11:30am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/5 "2005-06-29T11:30:29Z")

</div>

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\classes.zip

---

<div class="post-metadata">

**Author:** ![DougC](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@DougC](https://boards.straightdope.com/u/DougC)\
**Post date:** [June 29, 2005, 8:30pm UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/6 "2005-06-29T20:30:57Z")

</div>

- 
  - 
    - You might try a GUI front end if the CLI is the particular cause of problems:  
[http://www.netbeans.org/](http://www.netbeans.org/) - is open-source,  
[http://www.jcreator.com/](http://www.jcreator.com/) - has a freeware version.  
Other than that I can’t help you.  
~

---

<div class="post-metadata">

**Author:** ![Noone\_Special](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/noone_special/32/2863_2.png) [@Noone\_Special](https://boards.straightdope.com/u/Noone_Special)\
**Post date:** [June 29, 2005, 9:18pm UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/7 "2005-06-29T21:18:55Z")

</div>

Another good GUI (in fact, a complete Java IDE) is [Eclipse](http://www.eclipse.org)

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!

Dani

---

<div class="post-metadata">

**Author:** ![minor7flat5](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minor7flat5/32/258_2.png) [@minor7flat5](https://boards.straightdope.com/u/minor7flat5)\
**Post date:** [June 30, 2005, 1:30am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/8 "2005-06-30T01:30:40Z")

</div>

> [@Noone Special](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![Noone\_Special](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/noone_special/32/2863_2.png) [@Noone\_Special](https://boards.straightdope.com/u/Noone_Special)\
**Post date:** [June 30, 2005, 4:26am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/9 "2005-06-30T04:26:36Z")

</div>

> [@minor7flat5](#):
>
> 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) ☹

---

<div class="post-metadata">

**Author:** ![bluecanary](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bluecanary/32/3614_2.png) [@bluecanary](https://boards.straightdope.com/u/bluecanary)\
**Post date:** [June 30, 2005, 8:41am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/10 "2005-06-30T08:41:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Noone\_Special](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/noone_special/32/2863_2.png) [@Noone\_Special](https://boards.straightdope.com/u/Noone_Special)\
**Post date:** [June 30, 2005, 8:56am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/11 "2005-06-30T08:56:27Z")

</div>

> [@bluecanary](#):
>
> 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.

HOH

Dani

---

<div class="post-metadata">

**Author:** ![bluecanary](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bluecanary/32/3614_2.png) [@bluecanary](https://boards.straightdope.com/u/bluecanary)\
**Post date:** [June 30, 2005, 9:00am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/12 "2005-06-30T09:00:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Noone\_Special](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/noone_special/32/2863_2.png) [@Noone\_Special](https://boards.straightdope.com/u/Noone_Special)\
**Post date:** [June 30, 2005, 9:37am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/13 "2005-06-30T09:37:44Z")

</div>

> [@bluecanary](#):
>
> 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 – [http://java.sun.com](http://java.sun.com)

For back-compatabiliy issues, [this page](http://java.sun.com/j2se/1.5.0/compatibility.html) is probably a good starting point.

Dani

---

<div class="post-metadata">

**Author:** ![minor7flat5](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minor7flat5/32/258_2.png) [@minor7flat5](https://boards.straightdope.com/u/minor7flat5)\
**Post date:** [June 30, 2005, 11:23am UTC](https://boards.straightdope.com/t/compiling-java-in-windows-command-prompt/310340/14 "2005-06-30T11:23:41Z")

</div>

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:  
xerces.jar  
jaxp.jar  
log4j.jar  
log4j-core.jar  
crimson.jar

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 :))
