大佬教程收集整理的这篇文章主要介绍了如何从 Maven 生成新的 SOAP 网络服务?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我必须为我的团队制作文档。这个文档应该展示如何从头开始生成一个 webservice 项目,编译它并将其部署到 payara (glassfish) 服务器中
为了实现这个项目,我写了一个简单的项目,其主要文件是:
pom.xml
<?xml version="1.0" enCoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLscheR_881_11845@a-instance"
xsi:scheR_881_11845@aLOCATIOn="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupID>fr.inrae.sicpa</groupID>
<artifactID>MyserviceWS</artifactID>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>MyserviceWS</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<propertIEs>
<enCoding>UTF-8</enCoding>
<project.build.sourceEnCoding>UTF-8</project.build.sourceEnCoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</propertIEs>
<dependencIEs>
<!-- https://mvnrepository.com/artifact/jakarta.jws/jakarta.jws-API -->
<dependency>
<groupID>jakarta.jws</groupID>
<artifactID>jakarta.jws-API</artifactID>
<version>2.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-API -->
<dependency>
<groupID>jakarta.xml.bind</groupID>
<artifactID>jakarta.xml.bind-API</artifactID>
<version>2.3.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.xml.soap/jakarta.xml.soap-API -->
<dependency>
<groupID>jakarta.xml.soap</groupID>
<artifactID>jakarta.xml.soap-API</artifactID>
<version>1.4.2</version>
</dependency>
</dependencIEs>
<build>
<finalname>MyserviceWS</finalname>
<directory>${Basedir}/target</directory>
<!-- main -->
<sourceDirectory>${Basedir}/src/main/java</sourceDirectory>
<outputDirectory>${Basedir}/target/classes</outputDirectory>
<!-- test -->
<testsourceDirectory>${Basedir}/src/test/java</testsourceDirectory>
<testOutputDirectory>${Basedir}/target/test-classes</testOutputDirectory>
<resources>
<resource>
<directory>${Basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>*.propertIEs</include>
<include>*.xml</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<pluginManagement><!-- lock down plugins versions to avoID using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle,see https://maven.apache.org/ref/current/maven-core/lifecycles.HTML#clean_lifecycle -->
<plugin>
<artifactID>maven-clean-plugin</artifactID>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle,jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.HTML#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactID>maven-resources-plugin</artifactID>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactID>maven-compiler-plugin</artifactID>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactID>maven-surefire-plugin</artifactID>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactID>maven-war-plugin</artifactID>
<version>3.2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warsourceDirectory>${Basedir}/src/main/webapp/WebContent</warsourceDirectory>
<warsourceExcludes>${Basedir}/src/main/webapp/WEB-INF/web.xml</warsourceExcludes>
</configuration>
</plugin>
<plugin>
<artifactID>maven-install-plugin</artifactID>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactID>maven-deploy-plugin</artifactID>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle,see https://maven.apache.org/ref/current/maven-core/lifecycles.HTML#site_lifecycle -->
<plugin>
<artifactID>maven-site-plugin</artifactID>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactID>maven-project-info-reports-plugin</artifactID>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
src/main/webapp/WEB-INF/web.xml
<?xml version="1.0" enCoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLscheR_881_11845@a-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:scheR_881_11845@aLOCATIOn="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>MyserviceWS</display-name>
<welcome-file-List>
<welcome-file>index.HTML</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.Jsp</welcome-file>
<welcome-file>default.HTML</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.Jsp</welcome-file>
</welcome-file-List>
</web-app>
src/main/webapp/WEB-INF/payara-web.xml
<?xml version="1.0" enCoding="UTF-8"?>
<!DOCTYPE payara-web-app PUBliC
"-//Payara.fish//DTD Payara Server 4 Servlet 3.0//EN"
"https://raw.githubusercontent.com/payara/Payara-Server-documentation/master/scheR_881_11845@as/payara-web-app_4.dtd">
<payara-web-app>
<context-root>/MyserviceWS</context-root>
</payara-web-app>
/src/main/java/fr/inrae/sicpa/services/IMyservice.java
package fr.inrae.sicpa.services;
import javax.jws.Webservice;
@Webservice(name="IMyservice",targetnamespace="http://services.sicpa.inra.fr")
public interface IMyservice
{
public double getPrixTTC( double ht );
public double getPrixHT( double ttc );
public double getTVA( double prix,Boolean isTTC );
}
/src/main/java/fr/inrae/sicpa/services/MyserviceImpl.java
package fr.inrae.sicpa.services;
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.Webservice;
import javax.jws.soap.soAPBinding;
import javax.jws.soap.soAPBinding.Style;
import javax.jws.soap.soAPBinding.Use;
@Webservice(servicename="MyserviceWS",portname="MyservicePort",endpoinTinterface="fr.inrae.sicpa.MyserviceWS")
@SOAPBinding(style=Style.document,use=Use.literaL)
public class MyserviceImpl implements IMyservice
{
private final static double TAUX = 0.196;
@WebMethod(operationname="getPrixTTC")
@WebResult(name = "ttc")
@OverrIDe
public double getPrixTTC(double ht)
{
return ht * (1 + TAUX);
}
@WebMethod(operationname="getPrixHT")
@WebResult(name = "ht")
@OverrIDe
public double getPrixHT(double ttC)
{
return ttc / (1 + TAUX);
}
@WebMethod(operationname="getTVA")
@WebResult(name = "tva")
@OverrIDe
public double getTVA(double prix,Boolean isTTC)
{
if(isTTC)
return prix - (prix/(1 + TAUX));
else
return prix * TAUX;
}
}
在这个阶段,我设法生成我的项目结构,编译项目并将其部署在我的 payara 服务器 (5.192) 上。但我不明白的是,wsdl 文件和端点都不是在部署时创建的。
自 12 月底以来,我一直在为此苦苦挣扎。你认为我的错误在哪里?
非常感谢您的帮助
蒂埃里
感谢 RagnarosLightLord 在 Discord 上找到了解决方案:
嗨
有一个名为 cxf-java2ws-plugin 的 apache 插件可以预生成
编译 maven 时的 wsdl 文件。
看看这边,它会帮助你
祝你好运
拉格纳罗斯光明领主
这里是如何修改 pom.xml 以便在编译 maven 时能够生成 wsdl 文件:
<build>
...
...
<plugins>
<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>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-simple</artifactId>
<version>${Cxf.version}</version>
</dependency>
</dependencies>
<EXECUTIONS>
<execution>
<id>generate-wsdl</id>
<phase>process-classes</phase>
<configuration>
<attachWsdl>true</attachWsdl>
<className>fr.inrae.sicpa.services.MyserviceImpl</className>
<outputFile>${project.build.outputDirectory}/${project.build.finalNamE}.wsdl</outputFile>
<!-- See here for options http://cxf.apache.org/docs/java-to-ws.html -->
<databinding>jaxb</databinding>
<frontend>jaxws</frontend>
<genClient>false</genClient>
<genServer>false</genServer>
<genWrapperbean>false</genWrapperbean>
<genWsdl>true</genWsdl>
<quiet>false</quiet>
<verbose>true</verbose>
</configuration>
<goals>
<goal>java2ws</goal>
</goals>
</execution>
</EXECUTIONS>
</plugin>
</plugins>
...
...
</build>
以上是大佬教程为你收集整理的如何从 Maven 生成新的 SOAP 网络服务?全部内容,希望文章能够帮你解决如何从 Maven 生成新的 SOAP 网络服务?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。