0

I want to run a java class in UNIX and my java class, test.class is inside a folder with the name like test-java-1.0.1. So to run this java class I am using below command in UNIX:

$java -cp lib.jar  test-java-1.0.1/test

When I do this getting error as:

Exception in thread "main" java.lang.NoClassDefFoundError: test-java-1/0/1/test

How can I use .in the java class path?

Thanks, Eshwari

Aleksandr Podkutin
  • 2,532
  • 1
  • 20
  • 31

3 Answers3

0

You would wrap the path using quotations.

In your case, the command would be:

java -cp lib.jar "test-java-1.0.1/test"
0

Look at below links on Compiling with Java & Javac. I have given answer there.

  1. Compile and run Eclipse Project from command prompt
  2. Java Command line operations Example
  3. Build Eclipse Java Project from Command Line

Hope this will help you to solve the problem.

Community
  • 1
  • 1
OO7
  • 2,785
  • 1
  • 21
  • 33
0

If your class is called test (without any package) and the resulting compiled class has been put inside a folder called test-java-1.0.1, then you need to mention that folder as part of your classpath and provide the name of your class to the java executable:

java -cp test-java-1.0.1:lib.jar test

On Unix, you can concatenate multiple classpath element with colon ':'. On Windows, you need to use the semicolon ';'.

Note to improve:

  • Your class names should start with an upper-case letter
  • It's always better to put your class inside packages.

For example

package my.nice.package1;

public class Test {
    // Your code here

    public static void main(String[] args) {
          // Do something
    }
}

And then to invoke your class:

java -cp test-java-1.0.1:lib.jar my.nice.package1.Test
Guillaume Polet
  • 47,259
  • 4
  • 83
  • 117