wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""javac" but no "java"" Watch ""javac" but no "java"" New topic
Author

"javac" but no "java"

Reilly Morris
Ranch Hand

Joined: Sep 11, 2001
Posts: 44
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


<b>Reilly</b> <br /><i>SCJP,J2EE,OOAD,iNet+,A+,CIW,<br />MCP,--</i>
Kris Nelson
Ranch Hand

Joined: Nov 04, 2001
Posts: 35
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).]


WebNelly.com<br />Java/XML Web Development<br />Check it out!<br /><a href="http://www.webnelly.com" target="_blank" rel="nofollow">http://www.webnelly.com</a>
Reilly Morris
Ranch Hand

Joined: Sep 11, 2001
Posts: 44
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

Joined: Oct 31, 2001
Posts: 54
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).]


PAS<br />peter@panvox.net<br />2b || !2b
Reilly Morris
Ranch Hand

Joined: Sep 11, 2001
Posts: 44
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

Joined: Oct 31, 2001
Posts: 54
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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


GenRocket - Experts at Building Test Data
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: "javac" but no "java"
 
Similar Threads
Compilation errors scrolling off the screen
Java Enviroment Variables
Import Problems
Java code to compile and run another java program
error when testing...any help will be appreciated