【问题标题】:Soap Webservice Client for JAVAFX Application用于 JAVAFX 应用程序的 Soap Web 服务客户端
【发布时间】:2021-07-13 14:49:10
【问题描述】:

我正在尝试为我的应用程序调用 Web 服务。如果我在示例项目中调用它,它工作得非常好。但是当我将它与 My Java FX 合并时,它给了我很多错误。 Web Service Client 是使用 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 文件中间接引用的

【问题讨论】:

  • 错误告诉你Java找不到org.w3c.dom.ElementTraversal类。考虑到它是标准库的一部分,我觉得这很奇怪......
  • org.w3c.dom.ElementTraversal 类仅添加到 Java 9 中的标准 Java 库中,并且此问题标记为 javafx-8,因此提问者可能使用的是 Java 8 而不是更高版本的 Java。
  • 与问题无关,但当 JavaFX 具有可以使用的内置对话框时,我不建议在 JavaFX 应用程序中使用 JOptionPane(或其他 Swing 或 AWT 类)。跨度>
  • @jewelsea 我一定是在单独运行它时添加了它,但忘了删除。感谢您的建议。
  • @jewelsea 我已经编辑了这个问题,如果你现在可以帮助我。谢谢

标签: java soap-client webservice-client javafx-11


【解决方案1】:

好的,这不是一个真正的答案,更多关于相关问题的指针和提出解决方案的潜在方法。但我会将其发布为答案,因为这样做可能比许多 cmets 更好。

很遗憾,您有多个错误和问题,因此我将尝试分别处理其中的一些。


根据:

错误:

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

这里有一些关于发生了什么的信息:

这个修复对我来说似乎很棘手。请查看链接的问题和解决方案。看起来你要么需要要么

  1. 放弃 Java 9+ 模块化或
  2. 管理您的依赖项以不包括违反传递性依赖项或
  3. 更改为不依赖损坏库的库(在这种情况下可能是首选解决方案)。

导致此问题的损坏库可能是您使用的jaxrpc 版本。我的猜测是,一些相关的 XML 库仅在 Java 9 中添加到标准 Java 中,但您使用的 jaxrpc 库是在此之前开发的。因此,jaxrpc 要么在其类中包含 XML 库,要么使用具有相同功能的传递库。这会导致冲突,因为 XML 库只能在项目中包含一次。


有关您的问题的更多信息在此答案中:

信息太丑了。 . .您可以阅读答案,它可能会帮助您也可能会阻止您。


您可以做一些事情来帮助解决这种情况

对此应该怎么做有点棘手,取决于您的技能水平以及如何解决或是否可以解决。我会就您可以做的一些事情提供一些建议,但还有其他选择。您比我更了解您的应用程序,因此您可能能够为您的应用程序提出更好的解决方案。

我建议将这些东西分开,作为一种故障排除方法,获取一个与所有 JavaFX 组件一起使用的项目,以及一个与所有 SOAP 组件一起使用的项目,并确保它们构建并执行您想要的操作.然后尝试通过将这两个项目集成到一个项目中或在单独的虚拟机中运行它们并在两者之间进行通信来组合这两个项目(例如,通过添加的 REST API,尽管这是一个更复杂的解决方案,所以在尝试之前请三思而后行)。

另外,升级到最新版本的 JavaFX。我认为它不会解决您的问题,但它不会受到伤害,并且最近的 JavaFX 版本中的一些改进可能已经完成了一些可能有助于缓解您的一些问题的事情(尽管不是全部,因为一些您的问题源于模块化项目中的 jaxrpc 使用,这与 JavaFX 无关)。

此外,可能更重要的是,考虑使用不同的 SOAP 客户端框架,该框架与模块化 Java 9+ 的交互比 jaxrpc 似乎具有的损坏实现更好。

就您是否应该使您的应用程序模块化(是否包括模块信息)而言,我真的不知道最适合您的方法。当然,无论您选择哪种方式,都会遇到问题。但是,问题以及解决方法会因选择的解决方案路径而异(我猜您在调查问题的过程中已经发现了)。

如有必要,将问题分解为单个单独的问题。如果您在解决每个单独的问题时需要帮助,请发布包含 minimal reproducible example 代码的新问题以复制问题。请注意,如果您这样做,代码绝对是最小的并且也是完整的,以便它只复制并询问一个问题,而不是多个问题的组合,并且问题被适当标记 - 例如。如果问题是关于 jaxrpc 和模块化的,它应该包括 jaxrpc 和模块化标签,并且没有 JavaFX 代码或标签(反之亦然),当然还有 pdf 代码或任何地方的依赖项,如果这不是问题的一部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    相关资源
    最近更新 更多