-7

So I am trying to compile some java codes from the the terminal without eclipse. I was following this tutorial https://www.mkyong.com/java/java-rmi-hello-world-example/ So I got the 3 java files downloaded and I compiled them with javac *.java no error and I got 3 .class file

but when I ran java ServerOperation I got

Exception in thread "main" java.lang.NoClassDefFoundError: ServerOperation (wrong name: com/mkyong/rmiserver/ServerOperation)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:312)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

I think I did not compile the files correctly but I don't know how to do it. what command should I use to compile?

update: Fixed after removing all the package declaration How do I mark this as resolved Special thanks to Tom for his useless comments

Jason Wu
  • 1
  • 5

1 Answers1

0

The compilation was correct.

However, your main class is placed in a package.

This is because of the first line of ServerOperation.java:

package com.mkyong.rmiserver;

In order to run the program, you have to include the package while running main class. That means you have to navigate to the root of package/directory (in this case, just before com folder).

While there type:

$ java com.mkyong.rmiclient.ServerOperation
kyriakosSt
  • 1,754
  • 2
  • 15
  • 33