This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft 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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compile Lines" Watch "Compile Lines" New topic
Author

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 ./ File1.java File2.java

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: File1.java 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 ./ File2.java

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
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

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 . File1.java File2.java

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
 
Similar Threads
mock question
basic instantiation question
a simple question, but......
a simple doubt - but ......
Runtime.getRuntime().exec doesnt execute some files