Search code examples
javajardroolsdrools-guvnor

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


I'm trying to run an Executable JAR file on another computer but i am encountering a "SEVERE" error: "Unable to load pom.properties fromMySoapUIProject-1.1.jar as jarPath cannot be found."

The error, linked below, is not produced if i execute the JAR on the PC that has the eclipse project of this application.

Error produced when executing JAR from Command Line on another computer

The MySoapUIProject-1.1.jar that the error refers to is a artifact JAR which i downloaded from KieWorkbench and packaged it into an Eclipse Drools project.

I am loading the Workbench artifact as the default kiesession in my application and then executing the business process contained in the artifact as follows:

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;
}    

The end goal is to have a Standalone Java Application which has the workbench artifact stored within the jar and i want to use the kmodule.xml and pom.properties stored within this jar for the KieContainer.

I've read that this error I'm experiencing could be caused by not launching the application from the default directory but i have attempted this and it still produces the same error.

I am inclined to think that this could be caused by a System Variable not existing when it should but i have installed Maven on the other computer im using for testing and ant. Still no luck.

I've also tried to import the project onto the test computer. 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.

So my question is: how do i resolve the error "Unable to load pom.properties fromMySoapUIProject-1.1.jar as jarPath cannot be found." so that my standalone java app can run on another computer?


Solution

  • I think this is more related to classpath and packaging management than Drools, as I notice you mentioned:

    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.

    and the keypoint is on the export. Normally I do packaging with Maven, because I would expect it to manage to either uberjar or shade, etc.

    If you use Eclipse export, I think you can try by selecting option "copy required libraries into a sub-folder (...)" and then making sure when you launch your jar you have all required "libraries" jar listed into classpath, e.g.:

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

    or

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

    for Windows.

    I think the problem you are experiencing is that your MySoapUIProject-1.1.jar is manually added to Eclipse classpath rather than managed via proper maven dependency, so when you're in the IDE is available as a .jar file on the filesystem while when you "Eclipse export" you're wrapping it inside another jar.

    Besides on a more Drools-related note if you have the KieWorkbench and the repo you could avoid manual operation which as above may be prone to errors and just use automatic Maven resolution as per the Drools documentation example which seems to be the most appropriate for your case?

    Hope this helps