NewToAndroid
NewToAndroid

Reputation: 581

Running Java Program from Command-line

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

Upvotes: 0

Views: 270

Answers (1)

Dave Newton
Dave Newton

Reputation: 160170

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.

Upvotes: 6

Related Questions