0

I want to run a Java file with the following source code:

package u0a1;
public class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Hello World!");

    }

}

To run the file I did the following things: C:\.. \u0\u0a1> javac HelloWorld.java (this works, class file is created) Then I try to run it with:

C:\..\u0> java u0a1.HelloWorld 

This step doesn't work. Main class could not be found.

I also tried

C:\..\u0\u0a1> java HelloWorld
C:\..\u0> java u0a1\HelloWorld 

None of them worked.

2 Answers 2

2

This is a piece i found somewhere else, worked for me.

Have you set your JAVA_HOME correctly? If not you have to work with the full path

Example: "C:\Program Files\Java\jdk1.7.0_51\bin\javac.exe" HelloWorld.java

If you have runtime issues, you should work it out like this

Select MAIN directory - not package directory

java u0a1/HelloWorld

If you have problems with CLASSPATH or JAVA_HOME - try this: "C:\Program Files\Java\jdk1.7.0_51\bin\javac.exe" HelloWorld.java

source: http://quandano.com/questions/how-to-run-a-java-file-within-a-package-from-cmd

Sign up to request clarification or add additional context in comments.

Comments

0

You are compiling a program of package , so it should compile this way

C:.. \u0\u0a1> javac -d . HelloWorld.java

here -d for creating package u0a1

and "." for from current working directory

after compiling this way a folder will create with name "u0a1"

then other thing will work properly

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.