File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"javac" but no "java"

 
Reilly Morris
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can javac applications, but cannot java. Keeps throwing ClassDefNotFound exception. I am compiling to the same directory as I am trying to Java from.
1. Save doc as tester.java
2. From DOS, javac tester.java return NO compile errors
3. From DOS, java tester throws CDNF error
Please help... any advice would be great.
Reilly Morris
 
Kris Nelson
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you typing after the "java" command on the command line. You shouldn't type the .class extension when you run a progam with the "java" command. Doing so would give you that error.
If not, show us a little code of what you're trying to do.
------------------
WebNelly.com
Java/XML Web Development
Check it out! http://www.webnelly.com
[This message has been edited by Kris Nelson (edited November 10, 2001).]
 
Reilly Morris
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code... just using this snippet to get "java" working.
class tester{
public static void main(String args[]){
System.out.print("test complete");
}
}
I am not typing anything after the "java" instruct... just:
java tester
Reilly... by the way, thank for the quick response...
 
Peter Simard
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make tester public.
<code>
public class tester
{
public static void main (String[] args)
{
System.out.println("Test complete.");
}
}
</code>
Also, by convention, classes start with a captial letter.
------------------
PAS
peter@panvox.net
2b | | !2b
[This message has been edited by Peter Simard (edited November 10, 2001).]
[This message has been edited by Peter Simard (edited November 10, 2001).]
 
Reilly Morris
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, even cut/paste your code into the file, javac works but java does not. Could the java.exe in the bin folder be faulty?
Reilly
 
Peter Simard
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unlikely.
Could you possibly be typing in java Tester rather than java tester?

------------------
PAS
peter@panvox.net
2b | | !2b
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem could be your classpath not being set properly or not at all. Depending on which version of the JDK you are running that is. I "think" prior to 1.3 you needed to set the classpath in your environment variables but after that sun changed it and you don't have to. I ALWAYS set it just to be safe.
Make sure your classpath is set to the same directory where you are java'ing from.
Let me know.

------------------
Happy Coding,
Gregg Bolinger
 
Jane Griscti
Ranch Hand
Posts: 3141
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reilly,
There are a few things you can check:
1. If you are getting a 'class not found' and the class is in the current directory make sure there is no package statement in the source file. If there is, the class must be in a directory below the current directory that has the same name as the package and you must call it using 'java packagename.classname'
2. If there is no package statement, be sure the filename and the public class name match exactly. If the class is spelt 'tester' the filename must be 'tester.java', not 'Tester.java'
Hope that helps.

------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform

[This message has been edited by Jane Griscti (edited November 10, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic