5 Replies Latest reply on Nov 6, 2014 8:25 AM by psiroky

    How to add my own Java file to a BRMS project with a Decision Table

    x100

      Hello all,

       

      I have been trying to add a plain java source file to a BRMS project that has a) a decision-table and b) some POJOs created with the Data Modeler tool. When I add a java source file into the package everything is fine.

       

      The problem is when I import the decision-table into the BRMS application with the Import statement for the java source code I created. There is an error saying that the source file appears to be a package.

       

      Does anyone know how to fix this error? So that I can use the java source code I wrote with the decision table and POJOs created with the data modeler tool?

       

      Thank-you for reading this.

       

      Respectfully,

       

      Kyle Smith

        • 1. Re: How to add my own Java file to a BRMS project with a Decision Table
          psiroky

          Hello,

           

          the "the source file appears to be a package." error usually appears when the class cannot be found by the compiler. In order to make the class visible you need to add into your project under src/main/java/<appropriate-package> or you can add the POJOs in separate jar and then just add dependency on that jar into the project's pom.xml.

           

          If that is what you did and it still does not work, please share sources of your project so we can take a look. It is much easier to spot the problem when one actually sees the sources.

           

          Thanks,

          Petr

          1 of 1 people found this helpful
          • 2. Re: Re: How to add my own Java file to a BRMS project with a Decision Table
            x100

            Hi,

             

            Thank-you for the helpful answer Petr. I noticed that trying to upload my own java source file always results in the file be putting under the 'resources' folder and not in the same folder as the java POJO created with the data modeler. Do you know how to specify exactly where the uploaded source file goes?

             

            When I am using the JBoss BRMS and I am in my project and at the folder location I want and then click 'New Item' -> 'Uploaded File' the program adds it to the 'resources' folder without asking me where I would like the java source file to go. Please, see the screenshot to see what I mean.

            ResourcesFolder-FileUpload.PNG

             

            Also, if I create a Java Archive (JAR) out of my regular jar does the jar need a manifest?

             

            Thank-you for reading this.

             

            Also, here is the source-code I am trying to upload to my project:


            package com.kyleisawesome.foo;
            import com.kyleisawesome.foo.Planet; //my POJO created with the Data Modeler Tool


            public static class Space_Debris {
                ArrayList a = new ArrayList();


                public void addStuff(Object o) {
                    a.add(o);
                }


                public void listStuff(Object [] o){
               

                    for(Object a: o) {
                        if(a instanceof Planet){
                            Planet p3 = (Planet)a;
                            p3.getStatus();

                       }  else {

                           System.out.println("This was found in the 'Space_Debris' ArrayList: " + a);

                       }
                    } //end enhanced for loop
                } //end listStuff method
            } // end class

             

            Regards,

             

            Kyle Smith

            • 3. Re: How to add my own Java file to a BRMS project with a Decision Table
              psiroky

              I believe that the path "src/main/resources" is kind of hardcoded there in the current version, so there does not seem to a way around that in UI. However, what you can do is to clone the underlying git repository manually (see the Authoring-> Administration for the clone url, you need to use ssh in order to push the changes back), make the changes (e.g. add the file to the directory of your choice), commit and push them back to the repository. Then the files should be visible in the UI.

               

              Please create BZ (Log in to Red Hat Bugzilla) with the RFE for setting the destination directory when uploading files. I agree this would indeed be useful.

               

              Thanks,

              Petr

              1 of 1 people found this helpful
              • 4. Re: How to add my own Java file to a BRMS project with a Decision Table
                x100

                Petr,

                 

                How can I learn more about cloning 'the underlying git repository' and pushing changes etc? This is completely new to me. Thank-you for the helpful reply.

                 

                For instance I see the git and ssh URL but I try to access it using Putty and receive an error. How would you recommend accessing the repository?

                 

                Also, I created a Jar from this code:

                package com.kyleisawesome.foo;

                 

                 

                import java.util.ArrayList;

                 

                 

                public class Random_Debris {

                 

                 

                       ArrayList a = new ArrayList();

                 

                      public void addStuff(Object o) {

                          a.add(o);

                 

                      }

                 

                      public void listStuff(Object[] o){

                 

                          for(Object a: o) {

                 

                          System.out.println("Found this object in the ArrayList -> " + a);

                          }

                      }

                 

                 

                }

                When uploading my Decision-Table that contains the Import statement Import com.kyleisawesome.foo.Random_Debris. I receive the same import error I described to you earlier. Here is a screenshot of those errors:

                ImportError-JBoss.PNG

                I am not sure why this is though because I uploaded the jar I created to the BRMS Repository where the kjars are available when deployed.  I also added the group, artifactID, and version (GAV) information to the pom.xml file. That section of the pom.xml for my home-made jar, which contains the above code, looks like this:

                 

                dependency>

                            <groupId>com.kyleIsAwesome.Foo</groupId>

                            <artifactId>Debris</artifactId>

                            <version>2.0</version>

                            <scope>runtime</scope>

                </dependency>

                 

                 

                 

                I will also have to find some time to create the bug report in regards to the business-central UI behavior when adding my own java source file.

                 

                Respectfully,

                 

                Kyle Smith

                • 5. Re: How to add my own Java file to a BRMS project with a Decision Table
                  psiroky

                  If you are not familiar with git, I would recommend reading some tutorial and try the basic operations on newly created local repo. See for example http://git-scm.com/docs/gittutorial (or any other tutorial, there are dozens of them).

                   

                  You can clone your repository using the link shown in "Authoring -> Administration", it looks something like "ssh://localhost:<some-port>/<repo-name>". You can then clone the repository using "git clone <url-of-the-repo>". You can work with that repo as with any other. There are no KIE specific features there.

                   

                  If you have the "domain jar" (with the above class) properly defined in the "knowledge jar (kjar)", then that should work. If it is not workingm there maybe some configuration issue, or maybe even a bug. Could you upload your sources to e.g. github, so we could take a look? It is usually much faster to spot the error when we can see the actual changes.

                   

                  Thanks,

                  Petr