This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Compile Lines Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compile Lines" Watch "Compile Lines" New topic

Compile Lines

Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
Hi all,

How do I successfully compile java files with the following on the command line:

javac -deprecation -classpath ./

Is there anything I need to set up as I get errors? If I compile within an IDE it compiles fine (no error messages or warnings at all) and it works!

I get the following errors:
Note: uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Out of curiousity I still continue to run it qwith the following commands (the file where the main() is):
java -classpath ./

I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: File2/java

As I said, I don't get and errors or warnings when I compile within an IDE.

Thanks to all.

amerzil co-ed student<br />"Praise be the Code"
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24193

Hi Karen,

You did successfully compile the code; you just got some warnings. The "unsafe operation" warnings are benign, in any case. They're produced only by JDK 1.5. If your IDE is using an older JDK, or if it's passing the "-source 1.4" switch to this JDK, then you wouldn't see the warnings. They're nothing to worry about, really. Use

javac -source 1.4 -deprecation -classpath .

to make them go away.

Now, about the runtime errors: when you run a Java class, it's the "*.class" file, not the "*.java" file, that the "java" program uses. Furthermore, you don't tell java the name of the file, but rather the name of the class; in other words, to run from the command line, say

java -classpath . File2

[Jess in Action][AskingGoodQuestions]
Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
Hi Ernest,

Thank you.
subject: Compile Lines
It's not a secret anymore!