Java error: java.lang.NoClassDefFoundError with Maven on VSCODE

128 Views Asked by At

Hello i'm currently learning java i'm taking a course and we're diving into Maven proyects. The thing is that i'm getting an error when i tried to run a simple "Hello World" and my teacher couldn't find a solution

This is the code

package bmt;

/**
 * Hello world!
 *
 */
public class Saludo 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

This is the error

Error: Could not find or load main class Saludo
Caused by: java.lang.NoClassDefFoundError: bmt/Saludo (wrong name: Saludo)

I've seen multiple solutions but I just couldn't understand them or didn't work. This only happen with a Maven proyect and if I create a CLASSPATH a "Hello World" without Maven stops working too, can someone help me please

1

There are 1 best solutions below

1
Kartik Tiwari On

Steps for manual as it seems you have just started Java Programming Since your code looks like this it includes package you have to consider it.

package bds;

/**
 * Hello world!
 *
 */
public class Saludo 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

Suppose your directory looks like this

E:\Java\JustStarted
├───bds
└───src

just compile it by getting into your package

E:\Java\JustStarted\bds> javac Saludo.java

then go to the parent directory

cd ..

The console will look like this

E:\Java\JustStarted> 

Now just execute the Code here by typing

E:\Java\JustStarted> java bds/Saludo