users@jersey.java.net

[Jersey] Re: Error running "simple-service"

From: Daniel Trebbien <dtrebbien_at_gmail.com>
Date: Sun, 16 Jun 2013 19:46:57 -0400

Hello Kingsley,

You can get past this error by first executing mvn install:

$ mvn install
...

However, when I now run mvn exec:java, I get a NoClassDefFoundError, and I do not know how to fix it yet:

$ mvn exec:java
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building simple-service 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ simple-service >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ simple-service <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ simple-service ---
Jun 16, 2013 5:37:16 PM org.glassfish.jersey.server.ApplicationHandler initialize
INFO: Initiating Jersey application, version Jersey: 2.0 2013-05-14 20:07:34...
Jun 16, 2013 5:37:16 PM org.glassfish.jersey.internal.Errors logErrors
WARNING: The following warnings have been detected: WARNING: HK2 service reification failed for [org.glassfish.jersey.server.internal.inject.WebTargetValueFactoryProvider] with an exception:
MultiException stack 1 of 4
java.lang.NoClassDefFoundError: org/glassfish/jersey/client/ClientConfig
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2436)
        at java.lang.Class.getDeclaredMethods(Class.java:1793)
        at org.jvnet.hk2.internal.Utilities$3.run(Utilities.java:357)
        at org.jvnet.hk2.internal.Utilities$3.run(Utilities.java:353)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.jvnet.hk2.internal.Utilities.getDeclaredMethods(Utilities.java:353)
        at org.jvnet.hk2.internal.Utilities.getAllMethodKeys(Utilities.java:1215)
        at org.jvnet.hk2.internal.Utilities.getAllMethods(Utilities.java:1159)
        at org.jvnet.hk2.internal.Utilities.findInitializerMethods(Utilities.java:1243)
        at org.jvnet.hk2.internal.DefaultClassAnalyzer.getInitializerMethods(DefaultClassAnalyzer.java:97)
        at org.glassfish.jersey.internal.inject.JerseyClassAnalyzer.getInitializerMethods(JerseyClassAnalyzer.java:232)
...


My Java version is:
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06-451-11M4406)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01-451, mixed mode)

And I am running Mac OS 10.7.5.


Note that the error does not appear to stop the application from working (e.g. visiting http://localhost:8080/myapp/myresource results in "Got it!").

Does anyone know how to fix the NoClassDefFoundError?

Daniel Trebbien


On Jun 15, 2013, at 9:57 PM, kingsley osime wrote:

> hello,
>
> get class not found exception when trying to run simple-service app for first time. any ideas pls?
>
> openjdk_at_codeboxIII:~/simple-service7$ mvn -e clean exec:java
> [INFO] Error stacktraces are turned on.
> [INFO] Scanning for projects...
> [INFO]
> [INFO] ------------------------------------------------------------------------
> [INFO] Building simple-service7 1.0-SNAPSHOT
> [INFO] ------------------------------------------------------------------------
> [INFO]
> [INFO] --- maven-clean-plugin:2.3:clean (default-clean) @ simple-service7 ---
> [INFO]
> [INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ simple-service7 >>>
> [INFO]
> [INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ simple-service7 <<<
> [INFO]
> [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ simple-service7 ---
> [WARNING]
> java.lang.ClassNotFoundException: com.example.Main
> at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
> 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:423)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
> at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
> at java.lang.Thread.run(Thread.java:722)
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time: 5.521s
> [INFO] Finished at: Sun Jun 16 02:53:35 BST 2013
> [INFO] Final Memory: 7M/59M
> [INFO] ------------------------------------------------------------------------
> [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project simple-service7: An exception occured while executing the Java class. com.example.Main -> [Help 1]
> org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project simple-service7: An exception occured while executing the Java class. com.example.Main
> at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
> at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
> at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
> at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
> at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
> at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
> at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
> at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
> at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
> at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
> at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
> at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
> at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
> at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
> at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
> Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. com.example.Main
> at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:352)
> at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
> at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
> ... 19 more
> Caused by: java.lang.ClassNotFoundException: com.example.Main
> at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
> 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:423)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
> at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
> at java.lang.Thread.run(Thread.java:722)
> [ERROR]
> [ERROR] Re-run Maven using the -X switch to enable full debug logging.
> [ERROR]
> [ERROR] For more information about the errors and possible solutions, please read the following articles:
> [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
> openjdk_at_codeboxIII:~/simple-service7$