流口水;在另一台机器上执行时无法加载 pom.properties

Drools; Unable to load pom.properties when executing on another machine

我正在尝试 运行 另一台计算机上的可执行 JAR 文件,但遇到 "SEVERE" 错误:"Unable to load pom.properties fromMySoapUIProject-1.1.jar as jarPath cannot be found."

如果我在具有此应用程序的 eclipse 项目的 PC 上执行 JAR,则不会产生下面链接的错误。

Error produced when executing JAR from Command Line on another computer

错误所指的 MySoapUIProject-1.1.jar 是一个工件 JAR,我从 KieWorkbench 下载并将其打包到 Eclipse Drools 项目中。

我正在加载 Workbench 工件作为我的应用程序中的默认 kiesession,然后按如下方式执行工件中包含的业务流程:

public Person loadGuvnor(Person person) throws IOException{

    Person globalPerson = new Person();

    try 
    {
        KieServices kieServices = KieServices.Factory.get();
        KieRepository kieRepository = kieServices.getRepository();
        KieContainer kieContainer = kieServices.getKieClasspathContainer();
        KieSession myKieSession = kieContainer.newKieSession();

        myKieSession.insert(person);
        myKieSession.setGlobal("globalPerson", globalPerson);

        myKieSession.startProcess("MySoapUIProject.IDValidationProcess");
        myKieSession.fireAllRules();
        System.out.println("After Process Starts");

        globalPerson = (Person)myKieSession.getGlobal("globalPerson");

        System.out.println("Is the person a SACitizen?\t\t" + globalPerson.isSACitizen());
        System.out.println("Is the ID Valid?\t\t\t" + globalPerson.isValid());
        System.out.println("What is their Sequence Digits?\t\t" + globalPerson.getSequence());
        System.out.println("What is their DoB?\t\t\t" + globalPerson.getDateOfBirth().toString());
        System.out.println("What is their Age in Days this year?\t" + globalPerson.getAgeDays());
        System.out.println("What is their Age in Years?\t\t" + globalPerson.getAgeYears());
        System.out.println("what is their Gender?\t\t\t" + globalPerson.getGender());
        System.out.println("what is their Gender?\t\t\t" + globalPerson.getGenderText());

        return globalPerson;

    } catch (Exception e) 
    {
        e.printStackTrace();
    }

    return globalPerson;
}    

最终目标是拥有一个独立的 Java 应用程序,其中包含存储在 jar 中的 workbench 工件,我想使用存储的 kmodule.xml 和 pom.properties在这个用于 KieContainer 的罐子里。

我了解到我遇到的这个错误可能是由于没有从默认目录启动应用程序引起的,但我已经尝试过,但它仍然产生相同的错误。

我倾向于认为这可能是由于系统变量不存在而导致的,但我已经在另一台用于测试和 ant 的计算机上安装了 Maven。仍然没有运气。

我也试过将项目导入到测试计算机上。我可以成功导入它并且 运行 IDE 中的项目没有任何问题。但是后来我将它导出为 运行nable Jar,然后产生了与上面相同的错误。

所以我的问题是:如何解决错误 "Unable to load pom.properties fromMySoapUIProject-1.1.jar as jarPath cannot be found." 以便我的独立 java 应用程序可以 运行 在另一台计算机上?

我认为这比 Drools 更与类路径和打包管理相关,正如我注意到您提到的:

I can import it successfully and run the project in the IDE without any issue. But then i export it as a runnable Jar and then the same error as above is produced.

关键点在 export 上。通常我使用 Maven 进行打包,因为我希望它能够管理到 uberjar 或 shade 等。

如果您使用 Eclipse 导出,我认为您可以尝试选择选项 "copy required libraries into a sub-folder (...)",然后确保在启动 jar 时您已将所有必需的 "libraries" jar 列在类路径中,例如:

java -cp 'myJavaApp.jar:lib/*' your.package.MainClass

java -cp 'myJavaApp.jar;lib/*' your.package.MainClass

对于 Windows。

我认为您遇到的问题是您的 MySoapUIProject-1.1.jar 是手动添加到 Eclipse 类路径而不是通过适当的 maven 依赖项进行管理,所以当您在 IDE在文件系统上以 .jar 文件的形式提供,而当您 "Eclipse export" 将其包装在另一个 jar 中时。

除了与 Drools 更相关的说明之外,如果您拥有 KieWorkbench 和回购协议,您可以避免手动操作,如上所述,手动操作可能容易出错,只需按照 Drools documentation example 使用自动 Maven 解析,这似乎最适合您的情况?

希望对您有所帮助