0

I'm trying to run a JAVA Class under Linux Mint from the Terminal.

My Java class runs nice within any IDE, so I know it's not a code problem, but actually need to run it from the Command Line this time. However, I'm having issues at this point.

I used the following command:

java -cp . Interface

But it happens that it gives me an java.lang.NoClassDefFoundError Exception:

Exception in thread "main" java.lang.NoClassDefFoundError: Interface (wrong name: client/Interface)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:788)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:447)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

I'm looking to understand all the components that could make it possible to solve this issue and to be able to overcome future problems on the topic.

Thank you for your time.

2
  • what is the package name of Interface or its default? Commented Nov 26, 2013 at 14:29
  • Post your code (though it's likely the answer below hit the answer on the head) Commented Nov 26, 2013 at 14:35

2 Answers 2

4

Your class resides within the package client so you have to change the current directory to the parent directory and run it with java -cp . client.Interface. ls should show you a directory named client.

<current directory>
└ client
  └ Interface.class

So using the information you gave in the comments to another answer, your current directory should be NetBeansProjects/ServerClient/build/classes/ when starting the application using the above command line.

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

Comments

1

Provide package name as well:

java  -cp . client.Interface

Run this command from the Project root (aka at the same place where is your bin file)

Comments

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.