The following program is throwing error:
public class HelloWorld {
public static void main(String args[]) {
System.out.println(\"Hello World!\");
Easy & Simple solution: I solved this problem (NetBeans) by exporting the original project into zip file, deleting the original project directory and importing the project back from the zip file.
See http://scottizu.wordpress.com/2013/08/28/fixing-the-exception-in-thread-main-java-lang-noclassdeffounderror-in-eclipse/.
This is the long form of the Java commands that can be run from a Windows command prompt:
"C:\Program Files\Java\jdk1.6.0_18\bin\javac.exe" -classpath "C:\Users\Scott\workspace\myproject" com\mycompany\myapp\HelloWorld.java
"C:\Program Files\Java\jdk1.6.0_18\bin\java.exe" -classpath "C:\Users\Scott\workspace\myproject" com.mycompany.myapp.HelloWorld
Notice the classpath has no slash at the end. The javac.exe commands expects the file to end with ".java". The java.exe command expects the full class name and does not end with ".class".
There are a few ways to simplify these commands:
You don't have to enter the entire classpath (ie, you can just use -classpath "."). Enter the directory you will be working in:
cd "C:\Users\Scott\workspace\myproject\"
You can use the default package (put the HelloWorld.java file directory in your working directory and don't use the Java package directive)
If you make these changes you would run something like this (and you might be able to leave out -classpath "."):
cd "C:\Users\Scott\workspace\myproject\"
javac -classpath "." HelloWorld.java
java -classpath "." HelloWorld
Try doing
javac Hello.java
and then, if it comes up with no compiler errors (which it should not do because I cannot see any bugs in your programme), then type
java Hello
type the following in the cmd prompt, within your folder:
set classpath=%classpath%;.;
The Problem here is the setting the environment and the running of the class file. a. To set the environment path run the following command: set path=C:\Program Files (x86)\Java\jdk1.7.0\bin b. run the program from the package like com.test.TestJavaClass
Command: java com.test.TestJavaClass
The general issue here is we run it either from inside the package like src/package/name. We should not include src, package name is enough.
If you want to 'compile and execute' any java file that you have created using any IDE(like eclipse), just run the below commands:
Compile:
javac Users\dhiraj01\workspace\Practice\src\PracticeLogic\Logics.java
Execute:
java -classpath Users\dhiraj01\workspace\Practice\src\ PracticeLogic.Logics