• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile Lines

 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest,

Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic