1

I have a java project that has 10 .java files. A1.java, A2.java......A9.java and Main.java. I have to built and run that project in UNIX environment. All the 10 .java files reside inside grand.big.medium.small package. To compile the java file I go inside the grand/big/medium/small folder and type the command:

javac *.java

All the files gets compiled and all the .class files gets created in the current folder, also, I get the following message:

Note: A4.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: A4.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Now I run the Main.class be typing:

java -classpath . Main

and I get the error message:

Error: Could not find or load main class Main

I am new to Unix and do not know much about this, Could anyone tell what is that I am doing wrong. Just to add, I have 3 java version installed

 Selection    Path                                            Priority   Status
 ------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/jre/bin/java          1072      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
* 3            /usr/lib/jvm/java-8-oracle/jre/bin/java          1072      manual mode

 Press enter to keep the current choice[*], or type selection number: 

and I am using Java 8.

Learner
  • 449
  • 1
  • 7
  • 16

2 Answers2

4

After you compile, move up to the folder that contains the root of your package (which is grand given grand.big.medium.small) then you use

java -cp . grand.big.medium.small.Main
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

Use proper classpath and fully qualified main class as below:

java -classpath ../../..:. grand.big.medium.small.Main
SMA
  • 36,381
  • 8
  • 49
  • 73