百度到的答案都太乱了。。而且全是很老的答案,实际上用起来会报各种错误。
首先
WebService是一个很老的技术了,能选的话就别选它了。如果是对方用了webservice要求你去对接,也有别的选择,例如:
HttpClient ,自定义xml格式的字符串,用HTTP向对方接口发起请求。
其次
如果你莫得选择,只能用webservice,推荐JDK1.8版本,能直接调用接口
最后
如果你像我这样,项目用的新版本JDK,导致webservice一堆错误的话,
使用maven或者gradle依赖以下包
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>jakarta.xml.soap</groupId>
<artifactId>jakarta.xml.soap-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
注意:saaj-impl这个包要用1.5.2,不能用新版,不然会报下面这个错
Unable to create SAAJ meta-factory: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found
感谢以下链接的答者
https://stackoverflow.com/questions/48626824/java-lang-noclassdeffounderror-javax-xml-soap-soapexception
https://stackoverflow.com/questions/65791963/unable-to-create-saaj-meta-factory-provider-com-sun-xml-internal-messaging-saaj