vert.x icon indicating copy to clipboard operation
vert.x copied to clipboard

error NoClassDefFoundError when running verticle from command line

Open kumangxxx opened this issue 9 years ago • 3 comments

i tried to run my verticle from command line

vertx run TestVerticle.java

but i got an error saying NoClassDefFoundError:

Exception in thread "main" java.lang.NoClassDefFoundError: io/vertx/core/spi/VerticleFactory
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:370)
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
        at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
        at java.util.Iterator.forEachRemaining(Iterator.java:116)
        at io.vertx.core.ServiceHelper.loadFactories(ServiceHelper.java:61)
        at io.vertx.core.ServiceHelper.loadFactories(ServiceHelper.java:47)
        at io.vertx.core.impl.DeploymentManager.loadVerticleFactories(DeploymentManager.java:55)
        at io.vertx.core.impl.DeploymentManager.<init>(DeploymentManager.java:51)
        at io.vertx.core.impl.VertxImpl.<init>(VertxImpl.java:178)
        at io.vertx.core.impl.VertxImpl.<init>(VertxImpl.java:143)
        at io.vertx.core.impl.VertxFactoryImpl.vertx(VertxFactoryImpl.java:42)
        at io.vertx.core.Vertx.vertx(Vertx.java:90)
        at io.vertx.core.impl.launcher.commands.ClasspathHandler.create(ClasspathHandler.java:118)
        at io.vertx.core.impl.launcher.commands.BareCommand.startVertx(BareCommand.java:206)
        at io.vertx.core.impl.launcher.commands.BareCommand.run(BareCommand.java:145)
        at io.vertx.core.impl.launcher.commands.RunCommand.run(RunCommand.java:253)
        at io.vertx.core.impl.launcher.VertxCommandLauncher.execute(VertxCommandLauncher.java:230)
        at io.vertx.core.impl.launcher.VertxCommandLauncher.dispatch(VertxCommandLauncher.java:365)
        at io.vertx.core.impl.launcher.VertxCommandLauncher.dispatch(VertxCommandLauncher.java:328)
        at io.vertx.core.Launcher.main(Launcher.java:49)
Caused by: java.lang.ClassNotFoundException: io.vertx.core.spi.VerticleFactory
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

here's my TestVerticle.java:

package id.stroom.micros;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;

public class TestVerticle extends AbstractVerticle {

    @Override
    public void start(Future<Void> startFuture) throws Exception {
        System.out.println("verticle running");
        startFuture.complete();
    }

    @Override
    public void stop(Future<Void> stopFuture) throws Exception {
        System.out.println("Verticler stopped");
        stopFuture.complete();
    }
}

any idea what's wrong ? thanks!

kumangxxx avatar Sep 04 '17 06:09 kumangxxx

Hi, which version of vertx are you using? (vertx version)

This code, but without package id.stroom.micros; works fine:

$ cat > TestVerticle.java <<"EOF"
> import io.vertx.core.AbstractVerticle;
> import io.vertx.core.Future;
>
> public class TestVerticle extends AbstractVerticle {
>
>     @Override
>     public void start(Future<Void> startFuture) throws Exception {
>         System.out.println("verticle running");
>         startFuture.complete();
>     }
>
>     @Override
>     public void stop(Future<Void> stopFuture) throws Exception {
>         System.out.println("Verticler stopped");
>         stopFuture.complete();
>     }
> }
> EOF
$ vertx run TestVerticle.java
verticle running
Succeeded in deploying verticle

Sammers21 avatar Jan 10 '18 20:01 Sammers21

I think that in order to run it with specific packge you should comiple it (with javac as illustrated below or with $YOUR_FAVORITE_BUILD_TOOL):

$ mkdir -p ./id/stroom/micros
$ cd id/stroom/micros/
$ cat > TestVerticle.java <<"EOF"
>
> package id.stroom.micros;
>
> import io.vertx.core.AbstractVerticle;
> import io.vertx.core.Future;
>
> public class TestVerticle extends AbstractVerticle {
>
>     @Override
>     public void start(Future<Void> startFuture) throws Exception {
>         System.out.println("verticle running");
>         startFuture.complete();
>     }
>
>     @Override
>     public void stop(Future<Void> stopFuture) throws Exception {
>         System.out.println("Verticler stopped");
>         stopFuture.complete();
>     }
> }
> EOF
$ cd -
$ wget http://central.maven.org/maven2/io/vertx/vertx-core/3.5.0/vertx-core-3.5.0.jar
$ javac id/stroom/micros/TestVerticle.java -cp vertx-core-3.5.0.jar
$ vertx run id.stroom.micros.TestVerticle
verticle running
Succeeded in deploying verticle

Sammers21 avatar Jan 10 '18 20:01 Sammers21

@kumangxxx if you want to run a verticle with such a package name, create an id/stroom/micros directory and run vertx run id/stroom/micros/TestVerticle.java

If you don't do this, Vert.x should complain like this:

java.lang.RuntimeException: Package structure does not match directory structure

Which makes me think that you rather have a CLI installation problem.

tsegismont avatar Jan 11 '18 09:01 tsegismont