简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM