You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Thomas Chang <th...@yahoo.de> on 2011/09/07 15:47:03 UTC

Get "java.lang.NoClassDefFoundError" though the class is in the classpath

Hi all,

As I run mvn clean install I got exception as follow:

...
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.937s
[INFO] Finished at: Wed Sep 07 15:35:37 CEST 2011
[INFO] Final Memory: 8M/20M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:jaxws-maven-plugin:1.10:wsgen (default) on project TestWebService: Failed to execute wsgen:
 com/sun/mirror/apt/AnnotationProcessorFactory: com.sun.mirror.apt.AnnotationProcessorFactory -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:jaxws-maven-plugin:1.10:wsgen (default) on
project TestWebService: Failed to execute wsgen
        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:319)
        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: Failed to execute wsgen
        at org.codehaus.mojo.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:102)
        at org.codehaus.mojo.jaxws.MainWsGenMojo.execute(MainWsGenMojo.java:14)
        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.NoClassDefFoundError: com/sun/mirror/apt/AnnotationProcessorFactory
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
        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 org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:386)
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
        at com.sun.tools.ws.WsGen.doMain(WsGen.java:69)
        at org.codehaus.mojo.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:97)
        ... 22 more
Caused by: java.lang.ClassNotFoundException: com.sun.mirror.apt.AnnotationProcessorFactory
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
        ... 37 more
...

I know the class "com.sun.mirror.apt.AnnotationProcessorFactory" is in the tools.jar so I've add the dependency in the pom.xml as follow:

..
        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>C:/Program Files/Java/jdk1.7.0/lib/tools.jar</systemPath>
        </dependency>
...

As I run mvn dependency:build-classpath to check the included jars I can see the tools.jar in included.

Why I still get the ClassNotFoundException ?

Regards

Thomas


Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath

Posted by Thomas Chang <th...@yahoo.de>.
You are absolutellly right!

The pom.xml is used since a long time from JDK 1.5. I am too lazy to update it. :-/


--- Stephen Coy <st...@resolvesw.com> schrieb am Fr, 9.9.2011:

Von: Stephen Coy <st...@resolvesw.com>
Betreff: Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath
An: "Maven Users List" <us...@maven.apache.org>
Datum: Freitag, 9. September, 2011 09:24 Uhr

Hi Thomas,

I've been following this thread across from the m2e users list.

As you appear to be using Java 7, you had a long list of dependencies in your pom that are not needed, as they are provided by the JDK (since about 1.6.03 or thereabouts). So, be sure to get rid of the all of the jax-ws and jaxb dependencies that you have there.

We're using the jax-ws plugin for wsimport like this:

           <plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>jaxws-maven-plugin</artifactId>
            <version>1.12</version>
               <executions>
                   <execution>
                       <goals>
                           <goal>wsimport</goal>
                       </goals>
                       <configuration>
                           <wsdlDirectory>${project.build.directory}/wsdl</wsdlDirectory>
                           <wsdlLocation>META-INF/wsdl/InsurancePolicyService.wsdl</wsdlLocation>
                           <extension>true</extension>
                           <target>2.1</target>
                           <xadditionalHeaders>true</xadditionalHeaders>
                       </configuration>
                   </execution>
               </executions>
           </plugin>

and that's all we need in a JDK 6 environment. There are no other dependencies needed for the plugin or the application code. In particular, there is no "tools.jar" system dependency.

Cheers,

Steve C


On 09/09/2011, at 4:05 PM, Thomas Chang wrote:

> But using the option -X doesn't tell me to move the <dependency/> into the <plugin/> section, right? :-/
> 
> 
> 
> --- Wayne Fay <wa...@gmail.com> schrieb am Do, 8.9.2011:
> 
> Von: Wayne Fay <wa...@gmail.com>
> Betreff: Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath
> An: "Maven Users List" <us...@maven.apache.org>
> Datum: Donnerstag, 8. September, 2011 22:49 Uhr
> 
>> You are right. After I move the dependency into the plugin section, it works.
> 
> For future use, the -X is a parameter that turns on debug mode. So
> instead of "mvn compile" you run "mvn -X compile". The error message
> you got said basically "you didn't tell me what to do with this
> project so I will quit now."
> 
> Wayne
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath

Posted by Stephen Coy <st...@resolvesw.com>.
Hi Thomas,

I've been following this thread across from the m2e users list.

As you appear to be using Java 7, you had a long list of dependencies in your pom that are not needed, as they are provided by the JDK (since about 1.6.03 or thereabouts). So, be sure to get rid of the all of the jax-ws and jaxb dependencies that you have there.

We're using the jax-ws plugin for wsimport like this:

           <plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>jaxws-maven-plugin</artifactId>
	        <version>1.12</version>
               <executions>
                   <execution>
                       <goals>
                           <goal>wsimport</goal>
                       </goals>
                       <configuration>
                           <wsdlDirectory>${project.build.directory}/wsdl</wsdlDirectory>
                           <wsdlLocation>META-INF/wsdl/InsurancePolicyService.wsdl</wsdlLocation>
                           <extension>true</extension>
                           <target>2.1</target>
                           <xadditionalHeaders>true</xadditionalHeaders>
                       </configuration>
                   </execution>
               </executions>
           </plugin>

and that's all we need in a JDK 6 environment. There are no other dependencies needed for the plugin or the application code. In particular, there is no "tools.jar" system dependency.

Cheers,

Steve C


On 09/09/2011, at 4:05 PM, Thomas Chang wrote:

> But using the option -X doesn't tell me to move the <dependency/> into the <plugin/> section, right? :-/
> 
> 
> 
> --- Wayne Fay <wa...@gmail.com> schrieb am Do, 8.9.2011:
> 
> Von: Wayne Fay <wa...@gmail.com>
> Betreff: Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath
> An: "Maven Users List" <us...@maven.apache.org>
> Datum: Donnerstag, 8. September, 2011 22:49 Uhr
> 
>> You are right. After I move the dependency into the plugin section, it works.
> 
> For future use, the -X is a parameter that turns on debug mode. So
> instead of "mvn compile" you run "mvn -X compile". The error message
> you got said basically "you didn't tell me what to do with this
> project so I will quit now."
> 
> Wayne
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath

Posted by Thomas Chang <th...@yahoo.de>.
But using the option -X doesn't tell me to move the <dependency/> into the <plugin/> section, right? :-/



--- Wayne Fay <wa...@gmail.com> schrieb am Do, 8.9.2011:

Von: Wayne Fay <wa...@gmail.com>
Betreff: Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath
An: "Maven Users List" <us...@maven.apache.org>
Datum: Donnerstag, 8. September, 2011 22:49 Uhr

> You are right. After I move the dependency into the plugin section, it works.

For future use, the -X is a parameter that turns on debug mode. So
instead of "mvn compile" you run "mvn -X compile". The error message
you got said basically "you didn't tell me what to do with this
project so I will quit now."

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath

Posted by Wayne Fay <wa...@gmail.com>.
> You are right. After I move the dependency into the plugin section, it works.

For future use, the -X is a parameter that turns on debug mode. So
instead of "mvn compile" you run "mvn -X compile". The error message
you got said basically "you didn't tell me what to do with this
project so I will quit now."

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath

Posted by Thomas Chang <th...@yahoo.de>.
Hi,

You are right. After I move the dependency into the plugin section, it works.

Many thanks!

Thomas

--- Wayne Fay <wa...@gmail.com> schrieb am Mi, 7.9.2011:

Von: Wayne Fay <wa...@gmail.com>
Betreff: Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath
An: "Maven Users List" <us...@maven.apache.org>
Datum: Mittwoch, 7. September, 2011 16:18 Uhr

> I know the class "com.sun.mirror.apt.AnnotationProcessorFactory" is in the tools.jar so I've add the dependency in the pom.xml as follow:
>
>             <systemPath>C:/Program Files/Java/jdk1.7.0/lib/tools.jar</systemPath>
>
> As I run mvn dependency:build-classpath to check the included jars I can see the tools.jar in included.

You probably don't want this in your build classpath but perhaps added
to the classpath of the jaxws plugin, right? Move the dependency there
and try again with mvn -X to see the full classpath used for that
plugin execution.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath

Posted by Thomas Chang <th...@yahoo.de>.
Hi,

How do you mean "Move the dependency there"? 

I run the mvn -X and get followings:

...

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.125s
[INFO] Finished at: Thu Sep 08 14:14:08 CEST 2011
[INFO] Final Memory: 2M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal>
 or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources
, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-te
st-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-
test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
org.apache.maven.lifecycle.NoGoalSpecifiedException: No goals have been specified for this build. You must specify a valid lifecycle phase o
r a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phase
s are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-te
st-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package
, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, s
ite, post-site, site-deploy.
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:104)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
        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)
[ERROR]
[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/NoGoalSpecifiedException
...


And my pom.xml looks as follow:

...
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        <!-- jax-ws -->
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.1.5</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.xml.bind</groupId>
                    <artifactId>jaxb-impl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.xml.bind</groupId>
                    <artifactId>jaxb-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.xml.stream</groupId>
                    <artifactId>stax-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.xml.soap</groupId>
                    <artifactId>saaj-api</artifactId>
                </exclusion>
                <!-- saaj-impl.jar darf auf keinen Fall im WAR landen! Dies führt zu 
                    einem Fehler bei pbv-internet-ear.ear -->
                <exclusion>
                    <groupId>com.sun.xml.messaging.saaj</groupId>
                    <artifactId>saaj-impl</artifactId>
                </exclusion>
                <!-- Bei JBoss 'activation' muss ausgeschlossen -->
                <!-- <exclusion> -->
                <!-- <groupId>javax.activation</groupId> -->
                <!-- <artifactId>activation</artifactId> -->
                <!-- </exclusion> -->
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
            <!-- Bei JBoss 'activation' muss ausgeschlossen -->
            <!-- <exclusions> -->
            <!-- <exclusion> -->
            <!-- <groupId>javax.activation</groupId> -->
            <!-- <artifactId>activation</artifactId> -->
            <!-- </exclusion> -->
            <!-- </exclusions> -->
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.1.9</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.stream</groupId>
            <artifactId>stax-api</artifactId>
            <version>1.0-2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>C:/Program Files/Java/jdk1.7.0/lib/tools.jar</systemPath>
        </dependency>
    </dependencies>
    <build>
        <finalName>TestWebService</finalName>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>1.10</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsgen</goal>
                        </goals>
                        <configuration>
                            <sei>com.wei.chen.MyWeb</sei>
                            <!--for demo purpose only, the webapp does not -->
                            <!--need the generated wsdl files -->
                            <genWsdl>true</genWsdl>
                            <keep>true</keep>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
...
--- Wayne Fay <wa...@gmail.com> schrieb am Mi, 7.9.2011:

Von: Wayne Fay <wa...@gmail.com>
Betreff: Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath
An: "Maven Users List" <us...@maven.apache.org>
Datum: Mittwoch, 7. September, 2011 16:18 Uhr

> I know the class "com.sun.mirror.apt.AnnotationProcessorFactory" is in the tools.jar so I've add the dependency in the pom.xml as follow:
>
>             <systemPath>C:/Program Files/Java/jdk1.7.0/lib/tools.jar</systemPath>
>
> As I run mvn dependency:build-classpath to check the included jars I can see the tools.jar in included.

You probably don't want this in your build classpath but perhaps added
to the classpath of the jaxws plugin, right? Move the dependency there
and try again with mvn -X to see the full classpath used for that
plugin execution.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Get "java.lang.NoClassDefFoundError" though the class is in the classpath

Posted by Wayne Fay <wa...@gmail.com>.
> I know the class "com.sun.mirror.apt.AnnotationProcessorFactory" is in the tools.jar so I've add the dependency in the pom.xml as follow:
>
>             <systemPath>C:/Program Files/Java/jdk1.7.0/lib/tools.jar</systemPath>
>
> As I run mvn dependency:build-classpath to check the included jars I can see the tools.jar in included.

You probably don't want this in your build classpath but perhaps added
to the classpath of the jaxws plugin, right? Move the dependency there
and try again with mvn -X to see the full classpath used for that
plugin execution.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org