gpt4 book ai didi

java - 使用 maven : CXF + java2ws goal 从 java 生成 WSDL

转载 作者:搜寻专家 更新时间:2023-11-01 03:43:42 30 4
gpt4 key购买 nike

是否有易于理解的教程显示如何使用 maven 和 cxf 目标 java2ws 从 java 代码生成 WSDL?

我想在包含 @WebService 注释类的项目上执行 mvn install 并在目标文件夹内的某处生成 WSDL,以便其他开发人员可以使用它生成订阅者类。

我还希望将 Web 服务包含到一个 jar 中,我可以将其部署在 Web 服务容器中,以便订阅者可以使用该服务。

到目前为止,我的 pom 看起来像这样:

<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<cxf.version>2.2.3</cxf.version>
</properties>


<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.0.9</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-wsdl</id>
<phase>process-classes</phase>
<goals>
<goal>java2ws</goal>
</goals>
<configuration>
<outputFile>${project.build.outputDirectory}/testService.wsdl</outputFile>
<className>complete.path.to.ClassName</className>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>


<pluginRepositories>
<pluginRepository>
<id>apache-snapshots</id>
<name>Apache SNAPSHOT Repository</name>
<url>http://repository.apache.org/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>


<repositories>
<repository>
<id>apache-snapshots</id>
<name>Apache SNAPSHOT Repository</name>
<url>http://repository.apache.org/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
</repositories>


<dependencies>
<!-- CXF WebService -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>

但是当我运行 maven install.. 没有 wsdl..

哦,对了,附加信息:我们正在以模块化方式开发。提供 WebService 的模块将包含其他处理来自前端模块的内部方法调用的类,并将构建为 jar 而不是 war。

希望有人能找到我遗漏的东西,或者可以给我指出一个好的教程。

编辑:使用 mvn org.apache.cxf:cxf-java2ws-plugin:java2ws 直接调用目标,但我得到一个 LifecycleExecutionException:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.cxf:cxf-java2ws-plugin:2.2.3:java2ws (default-cli) on project dw-person: The parameters 'className' for goal o
rg.apache.cxf:cxf-java2ws-plugin:2.2.3:java2ws are missing or invalid
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:221)
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:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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.PluginParameterException: The parameters 'className' for goal org.apache.cxf:cxf-java2ws-plugin:2.2.3:java2ws are missing or invalid
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:576)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:529)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:92)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more

然而,如上所示,className 参数存在并且路径也是正确的...有什么想法吗?

最佳答案

只为那些遇到与pluginManagement无关的麻烦的人.就我而言,对于 cxf.version 3.1.10 此事在<configuration>部分。将其上移至与 <executions> 相同的级别后是的,问题已经解决了。我在这里找到它:http://cxf.547215.n5.nabble.com/Strange-behavior-of-Maven-cxf-java2ws-plugin-td553742.html

这是来自 apache.org ( https://cxf.apache.org/docs/maven-java2ws-plugin.html ) 的示例:

<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>${cxf.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>

<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<configuration>
<className>full.class.name</className>
<genWsdl>true</genWsdl>
<verbose>true</verbose>
</configuration>
<goals>
<goal>java2ws</goal>
</goals>
</execution>
</executions>
</plugin>

这里是固定的:

<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>${cxf.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>

<configuration>
<className>full.class.name</className>
<genWsdl>true</genWsdl>
<verbose>true</verbose>
</configuration>

<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<goals>
<goal>java2ws</goal>
</goals>
</execution>
</executions>
</plugin>

关于java - 使用 maven : CXF + java2ws goal 从 java 生成 WSDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8225318/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com