Maven:执行wsgen时找不到tools.jar

时间:2014-01-20 13:21:41

标签: java maven jax-ws wsgen

我尝试使用Windows 8命令行中的jaxws:wsgen maven插件,但它失败了:

  

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

我知道这表明Maven在我的JDK中找不到tools.jar但是我不知道如何添加它(当然是安装了JDK)。

以下是我的配置的一些细节:

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"

所以我也尝试在我的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>

并执行

mvn -P default-tools.jar package

但我仍然得到ClassNotFoundException

完整输出:

  

[错误]无法执行目标   org.codehaus.mojo:jaxws-maven-plugin:1.10:wsgen(generate-wsdl)on   project WebService:无法执行wsgen:   COM /阳光/镜像/公寓/ AnnotationProcessorFactory:   com.sun.mirror.apt.AnnotationProcessorFactory - &gt; [帮助1]   org.apache.maven.lifecycle.LifecycleExecutionException:失败   执行目标org.codehaus.mojo:jaxws-maven-plugin:1.10:wsgen   项目WebService上的(generate-wsdl):无法执行wsgen           在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)           在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)           在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)           在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)           在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)           在org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)           在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)           在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)           在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)           在org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)           在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)           在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)           在org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)           在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)           在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)           在org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)   引起:org.apache.maven.plugin.MojoExecutionException:失败   执行wsgen           在org.codehaus.mojo.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:102)           在org.codehaus.mojo.jaxws.MainWsGenMojo.execute(MainWsGenMojo.java:14)           在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)           在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)           ... 19更多引起: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)           在java.net.URLClassLoader.access $ 100(URLClassLoader.java:71)           在java.net.URLClassLoader $ 1.run(URLClassLoader.java:361)           在java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)           at java.security.AccessController.doPrivileged(Native Method)           在java.net.URLClassLoader.findClass(URLClassLoader.java:354)           在org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:389)           在org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)           在org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)           在org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)           在org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)           在com.sun.tools.ws.WsGen.doMain(WsGen.java:69)           在org.codehaus.mojo.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:97)           ... 22更多引起:java.lang.ClassNotFoundException:com.sun.mirror.apt.AnnotationProcessorFactory           在org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)           在org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)           在org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)           在org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)           ......还有38个

同时将tools.jar放入我的本地存储库并没有解决我的问题。

有人知道下一步该尝试什么吗?

谢谢!

3 个答案:

答案 0 :(得分:2)

完整输出(插件有问题的某些上下文)会很有用。我不完全确定,但我认为jaxws maven插件缺少类,而不是你的应用程序,因此你应该将依赖项添加到该插件,而不是你的应用程序。


编辑:OP的评论代码,用于更好的读/复制/粘贴能力

<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>

答案 1 :(得分:0)

您可以尝试一些事情:因为这是java 7,将供应商更改为“Oracle Corporation”。

你还确定你有这条路吗? $ {java.home} /../ LIB / tools.jar中

仅出于测试原因,您可以默认激活此配置文件,看看是否有帮助,进一步缩小问题范围。

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

答案 2 :(得分:0)

将wsdl生成器从您正在使用的内容更改为:

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

所有配置都相同,但它适用于Java 7&amp; Java 8(和openjdk 8,fyi)。