0

I downloaded a java program that consists of two folders src and classes containing the source files and class files respectively. Now, the src and classes folders contain a several nested sub-folders wherein the last sub-folder contains the source and class files respectively. More precisely, the path to a source and class file is src/edu/univ/.java and classes/edu/univ/.class. Given that the file containing the main function is Main.java, how can I run this program from command-line.

I have tried:

 java  src/edu/univ/Main but I get Exception in thread "main" java.lang.NoClassDefFoundError: src/edu/univ/Main

I have also tried: java src.edu.univ.Main but I encounter a similar error

2
  • try java edu.univ.Main you have to use the fully qualified name of the class. Commented Nov 21, 2013 at 21:42
  • The src folder contains the Java source files. The executable clases are in classes/edu/... Commented Nov 21, 2013 at 21:44

1 Answer 1

6

From the root of the project:

java -cp classes edu.univ.Main

This tells the JRE that the classes directory is the root of your package hierarchy. The JRE will load packages from there, following the directory/package naming hierarchy.

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

2 Comments

clean this up for colon seperated paths
@AmirAfghani Irrelevant for the OP at this time.

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.