如何解决用于 JAVAFX 应用程序的 Soap Web 服务客户端
我正在尝试为我的应用程序调用网络服务。如果我在示例项目中调用它,它运行得非常好。但是当我将它与 My Java FX 合并时,它给了我很多错误。 Web 服务客户端是使用 Eclipse 自动生成的。我只想调用方法。有人可以帮我吗?
Error: **Correction** I have edited it and I am using Now JAVASE-15 and JVAFX-SDK 11.0.2
The package javax.xml.namespace is accessible from more than one module: java.xml,jaxrpc
Correction Update 2: I have removed Java.xml dependencies and module-info file as well.
but the new error is this
**Error: Could not find or load main class gload.Main
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application**
and IF I keep the module info file it shows:
**Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.graphics not found,required by gload**
型号:
package gload.model;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardcopyOption;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.JOptionPane;
import org.apache.pdfBox.pdmodel.PDDocument;
import org.apache.pdfBox.text.PDFTextStripper;
import org.datacontract.schemas._2004._07.PE_PPER_MyPdmWebServiceClient_Data.CustomerItem;
import org.datacontract.schemas._2004._07.PE_PPER_MyPdmWebServiceClient_Data.Result;
import org.tempuri.IService;
import org.tempuri.ServiceLocator;
public class PdmData
{
public String scode;
public boolean state = false;
public static String CdfFile;
public static String pdflocation;
public static String Custom_Ci;
public static String Generic_Ci;
public static String Mp_ref;
public static String Interface;
public static String Comments;
public static String PersoAppli;
public static String Code;
public static String Revision;
public static String Customer_Name;
public static String Customer_reference;
public static String getCode() {
return Code;
}
public static void setCode(String code) {
Code = code;
}
public static String getRevision() {
return Revision;
}
public static void setRevision(String revision) {
Revision = revision;
}
public static String getCustomer_Name() {
return Customer_Name;
}
public static void setCustomer_Name(String customer_Name) {
Customer_Name = customer_Name;
}
public static String getCustomer_reference() {
return Customer_reference;
}
public static void setCustomer_reference(String customer_reference) {
Customer_reference = customer_reference;
}
public static String getPersoAppli() {
return PersoAppli;
}
public static void setPersoAppli(String persoAppli) {
PersoAppli = persoAppli;
}
public static String getGeneric_Ci() {
return Generic_Ci;
}
public static void setGeneric_Ci(String generic_Ci) {
Generic_Ci = generic_Ci;
}
public static String getCdfFile() {
return CdfFile;
}
public static void setCdfFile(String cdfFile) {
CdfFile = cdfFile;
}
public static String getPdflocation() {
return pdflocation;
}
public static void setPdflocation(String pdflocation) {
PdmData.pdflocation = pdflocation;
}
public String Cdffile(String reference) {
ServiceLocator locator = new ServiceLocator(); -------->Web Service Locator and call
try {
IService basicHttpBinding_IService = locator.getBasicHttpBinding_IService();
Result result = basicHttpBinding_IService.getFilebyDcode(reference);
//To download the files
String link = result.getLocation();
System.out.println(link);
File out = new File("C:\\TempDownload\\" + reference +".zip"); //Creating a zip file to store the contents of download file
new Thread(new Download(link,out)).start();
//To Unzip the file
Path source = Paths.get("C:\\TempDownload\\" + reference +".zip");
Path target = Paths.get("C:\\TempDownload\\Unzip");
try {
unzipFolder(source,target);
System.out.println("Done");
} catch (IOException e) {
e.printstacktrace();
}
//Creating a File object for directory
File directoryPath = new File("C:\\TempDownload\\Unzip\\Pre Ppc" + reference + "A_Released");
//List of all files and directories
String[] contents = directoryPath.list();
System.out.println("List of files and directories in the specified directory:");
FilenameFilter pdffilter = new FilenameFilter() {
public boolean accept(File dir,String name) {
String lowercaseName = name.toLowerCase();
if (lowercaseName.endsWith(".pdf")) {
return true;
} else {
return false;
}
}
};
String[] contents1 = directoryPath.list(pdffilter);
for(String fileName : contents1) {
System.out.println(fileName);
setCdfFile(fileName);
setPdflocation(directoryPath.toString());
}
//To extract the Data From PDF
File file = new File(getPdflocation() + "\\" + getCdfFile());
//FileInputStream fis = new FileInputStream(file);
PDDocument document = PDDocument.load(file);
PDFTextStripper pdfReader = new PDFTextStripper();
String docText = pdfReader.getText(document);
System.out.println(docText);
document.close();
//To extract details from document
String CI_Ref = "CI Ref";
int pos ;
pos = docText.indexOf(CI_Ref);
setGeneric_Ci(docText.substring(pos+7,pos+15));
System.out.println("Generic CI: " + getGeneric_Ci());
//To get Details of CI
CustomerItem customerItem = basicHttpBinding_IService.getCiDetails(getGeneric_Ci());
setPersoAppli(customerItem.getPersoAppli());
setCode(customerItem.getCode());
setRevision(customerItem.getRevision());
setCustomer_Name(customerItem.getCustomerName());
setCustomer_reference(customerItem.getCustomerReference());
}catch (Exception e) {
e.printstacktrace();
JOptionPane.showMessageDialog(null,"Unable to reach Service : " + e.getMessage());
}
return getPersoAppli();
}
模块信息文件
module gload {
requires javafx.controls;
requires javafx.fxml;
requires java.desktop;
requires java.rmi;
requires java.base;
requires axis;
requires jaxrpc;
requires org.apache.pdfBox;
opens gload;
opens gload.views.main;
opens gload.utils;
opens gload.model;
opens gload.controllers;
opens org.tempuri;
opens org.datacontract.schemas._2004._07.PE_PPER_MyPdmWebServiceClient_Data;
}
如果我将 Jaxrpc 保留在类路径而不是模块路径中,我会收到这样的错误说明
无法解析 javax.xml.rpc.ServiceException 类型。它是从所需的 .class 文件间接引用的
解决方法
好的,这不是真正的答案,提供更多相关问题的指示以及提出解决方案的潜在方法。但我会将其作为答案发布,因为这样做可能比大量评论更好。
很遗憾,您有多个错误和问题,因此我会尝试单独处理其中的一些。
根据:
错误:
Error occurred during initialization of boot layer
java.lang.module.FindException:
Module X not found,required by Y
可能在 --module-path
错误且无法找到模块时发生。可能,这至少是您的问题之一。链接的答案是针对 Idea 的,我不使用 Eclipse,所以我不知道如何解决 Eclipse 中的问题,但也许您可以进行一些研究以找出答案。
关于:
The package javax.xml.namespace is accessible from more than one module
有一些关于这里发生的事情的信息:
这个修复对我来说很棘手。请查看链接的问题和解决方案。看起来你要么需要
- 放弃 Java 9+ 模块化或
- 管理您的依赖项以不包含违反的传递依赖项或
- 改用不依赖损坏库的库(在这种情况下可能是首选解决方案)。
导致此问题的损坏库很可能是您使用的 jaxrpc
版本。我的猜测是,一些相关的 XML 库仅在 Java 9 中添加到标准 Java 中,但您使用的 jaxrpc 库是在此之前开发的。因此,jaxrpc 要么在其类中包含 XML 库,要么使用执行相同操作的传递库。这会导致冲突,因为 XML 库只能包含在项目中一次。
有关您的问题的更多信息在此答案中:
信息太丑了。 . .您可以阅读答案,它可能对您有所帮助,也可能使您沮丧。
您可以采取一些措施来帮助解决问题
对此应该怎么做有点棘手,这取决于您的技能水平以及您如何或是否可以解决它。我会就你可以做的一些事情提供一些建议,但还有其他选择。您比我更了解您的应用程序,因此您可以为您的应用程序提出更好的解决方案。
我建议将这些东西分开,作为故障排除的一种方式,获得一个适用于所有 JavaFX 组件的项目和一个适用于所有 SOAP 组件的项目,并确保它们构建并执行您想要的操作.然后尝试通过将它们集成到一个项目中或在单独的 VM 中运行它们并在两者之间进行通信来组合这两个项目(例如,通过添加的 REST API,尽管这是一个复杂得多的解决方案,因此在尝试之前请仔细考虑) ).
另外,升级到最新版本的 JavaFX。我认为它不会解决您的问题,但它不会受到伤害,并且最近的 JavaFX 版本中的一些改进可能已经做了一些可能有助于缓解您的一些问题的事情(尽管不是全部,因为有些您的问题源于模块化项目中 jaxrpc 的使用,这与 JavaFX 无关)。
此外,可能更重要的是,考虑使用不同的 SOAP 客户端框架,与 jaxrpc 似乎具有的损坏实现相比,它与模块化 Java 9+ 的交互效果更好。
就您是否应该使您的应用程序模块化(包括模块信息与否)而言,我真的不知道最适合您的方法。当然,无论您选择哪种方式,都会遇到问题。但是,问题以及如何解决这些问题会因选择的解决方案路径而异(我猜您在调查问题的过程中已经发现了)。
如有必要,将问题分解为单个单独的问题。如果您在解决每个单独的问题时需要帮助,请发布包含 minimal reproducible example 代码以复制问题的新问题。请注意,如果您这样做,代码绝对是最小的并且也是完整的,以便它只复制和询问一个问题,而不是多个问题的组合,并且问题是适当的标记 - 例如如果问题是关于 jaxrpc 和模块化,它应该包括 jaxrpc 和模块化标签,没有 JavaFX 代码或标签(反之亦然),当然,如果这不是问题的一部分,那么肯定在任何地方的 pdf 代码或依赖项上。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。