Question

I try to use jaxws:wsgen maven plugin from Windows 8 command line, but it fails with:

java.lang.ClassNotFoundException: com.sun.mirror.apt.AnnotationProcessorFactory

I know this indicates Maven cannot find tools.jar in my JDK but I don't know how to add this (JDK is installed of course).

Here are some details about my configuration:

echo %JAVA_HOME%
C:\Java\jdk1.7.0_51

java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

mvn -version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 17:22:22+0200)
Maven home: C:\Program Files (x86)\apache-maven-3.1.1
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: C:\Java\jdk1.7.0_51\jre
Default locale: de_CH, platform encoding: Cp1252
OS name: "windows 8", version: "6.2", arch: "amd64", family: "windows"

So I also tried to add a profile section to my pom.xml:

<profiles>
    <profile>
        <id>default-tools.jar</id>
        <activation>
            <property>
                <name>java.vendor</name>
                <value>Sun Microsystems Inc.</value>
            </property>
        </activation>
        <dependencies>
            <dependency>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
                <version>1.7.0</version>
                <scope>system</scope>
                <systemPath>${java.home}/../lib/tools.jar</systemPath>
            </dependency>
        </dependencies>
    </profile>
</profiles>

and execute

mvn -P default-tools.jar package

but I still get the ClassNotFoundException.

Full output:

[ERROR] Failed to execute goal org.codehaus.mojo:jaxws-maven-plugin:1.10:wsgen (generate-wsdl) on project WebService: 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 (generate-wsdl) on project WebService: Failed to execute wsgen at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216) 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:317) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214) at org.apache.maven.cli.MavenCli.main(MavenCli.java:158) 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:606) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) 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:106) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 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:800) 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:389) at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227) 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.unsynchronizedLoadClass(ClassRealm.java:259) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227) ... 38 more

Also putting the tools.jar into my local repository did not solve my problem.

Does anybody has an idea what to try next?

Thanks!

Was it helpful?

Solution

The full output (some context what plugin is having problems) would be useful. I'm not entirely sure, but I think that the jaxws maven plugin is missing the classes, not your application, so you should add the dependency to that plugin, not your application.


EDIT: OP's code from comment for better read/copy/paste-ability

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>jaxws-maven-plugin</artifactId>
 <...>
 <dependencies>
  <dependency>
   <groupId>com.sun</groupId>
   <artifactId>tools</artifactId>
   <version>1.7</version>
   <scope>system</scope>
   <systemPath>${java.home}/../lib/tools.jar</systemPath>
  </dependency>
 </dependencies>
</plugin>

OTHER TIPS

A few thing you can try: since this is java 7 change the vendor to "Oracle Corporation".

Also are you sure you have this path? ${java.home}/../lib/tools.jar

For testing reason only, you could activate this profile by default and see if that helps, further narrowing the problem.

<activation>
  <activeByDefault>true</activeByDefault>
</activation>

Change your wsdl generator from what you are using to:

<plugin>
    <groupId>org.jvnet.jax-ws-commons</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.2</version>
</plugin>

All the configuration is the same, but it works with Java 7 & Java 8 (and openjdk 8, fyi).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top