0

I try to get a kieContainer from a project which I created over the KIE Workbench.

    String url = "http://dev.dsack.local:8080/kie-wb/maven2wb/ouTest/projectTest/1.0/projectTest-1.0.jar";
    ReleaseIdImpl releaseId = new ReleaseIdImpl("ouTest", "projectTest", "1.0");
    KieServices kieServices = KieServices.Factory.get();
    kieServices.getResources().newUrlResource(url);
    KieContainer kieContainer = kieServices.newKieContainer(releaseId);

When I open the url with a browser I can download the .jar but in the last line I get an error. I dont know what i'm doing wrong. I'm also not very familiar with maven. Can you please help me?

12:57:11.688 [main] DEBUG org.kie.scanner.MavenRepository - Unable to resolve artifact: ouTest:projectTest:pom:1.0
org.eclipse.aether.resolution.ArtifactResolutionException: Could not find artifact ouTest:projectTest:pom:1.0 in central (https://repo.maven.apache.org/maven2)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444) ~[aether-impl-1.0.0.v20140518.jar:na]
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246) ~[aether-impl-1.0.0.v20140518.jar:na]
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:223) ~[aether-impl-1.0.0.v20140518.jar:na]
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveArtifact(DefaultRepositorySystem.java:294) ~[aether-impl-1.0.0.v20140518.jar:na]
at org.kie.scanner.MavenRepository.resolveArtifact(MavenRepository.java:154) ~[kie-ci-6.4.0.Final.jar:6.4.0.Final]
at org.kie.scanner.ArtifactResolver.getPomFileForGAV(ArtifactResolver.java:148) [kie-ci-6.4.0.Final.jar:6.4.0.Final]
at org.kie.scanner.ArtifactResolver.getResolverFor(ArtifactResolver.java:108) [kie-ci-6.4.0.Final.jar:6.4.0.Final]
at org.kie.scanner.KieRepositoryScannerImpl.loadPomArtifact(KieRepositoryScannerImpl.java:151) [kie-ci-6.4.0.Final.jar:6.4.0.Final]
at org.kie.scanner.KieRepositoryScannerImpl.loadArtifact(KieRepositoryScannerImpl.java:127) [kie-ci-6.4.0.Final.jar:6.4.0.Final]
at org.kie.scanner.KieRepositoryScannerImpl.loadArtifact(KieRepositoryScannerImpl.java:122) [kie-ci-6.4.0.Final.jar:6.4.0.Final]
at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.loadKieModuleFromMavenRepo(KieRepositoryImpl.java:130) [drools-compiler-6.4.0.Final.jar:6.4.0.Final]
at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:116) [drools-compiler-6.4.0.Final.jar:6.4.0.Final]
at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:93) [drools-compiler-6.4.0.Final.jar:6.4.0.Final]
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:115) [drools-compiler-6.4.0.Final.jar:6.4.0.Final]
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:111) [drools-compiler-6.4.0.Final.jar:6.4.0.Final]
at controller.DecisionServerTest.test2(DecisionServerTest.java:163) [classes/:na]
at Main.main(Main.java:9) [classes/:na]
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact ouTest:projectTest:pom:1.0 in central (https://repo.maven.apache.org/maven2)
at org.eclipse.aether.connector.basic.ArtifactTransportListener.transferFailed(ArtifactTransportListener.java:39) ~[aether-connector-basic-1.0.0.v20140518.jar:na]
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:355) ~[aether-connector-basic-1.0.0.v20140518.jar:na]
at org.eclipse.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:67) ~[aether-util-1.0.0.v20140518.jar:na]
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$DirectExecutor.execute(BasicRepositoryConnector.java:581) ~[aether-connector-basic-1.0.0.v20140518.jar:na]
at org.eclipse.aether.connector.basic.BasicRepositoryConnector.get(BasicRepositoryConnector.java:249) ~[aether-connector-basic-1.0.0.v20140518.jar:na]
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:520) ~[aether-impl-1.0.0.v20140518.jar:na]
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:421) ~[aether-impl-1.0.0.v20140518.jar:na]
... 16 common frames omitted
Exception in thread "main" java.lang.RuntimeException: Cannot find KieModule: ouTest:projectTest:1.0
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:117)
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:111)
at controller.DecisionServerTest.test2(DecisionServerTest.java:163)
at Main.main(Main.java:9)
Marv174
  • 33
  • 7
  • Did you add `http://kiewbserver:8080/kie-drools-wb/maven2` to your maven settings? – raphaëλ Jul 27 '16 at 12:05
  • Wait you are using `newUrlResource`, try to use "LATEST" as the version – raphaëλ Jul 27 '16 at 12:08
  • No I haven't but I don't know how. I've created a settings.xml under Users/user1/.m2/ but I dont know how the content have to look like, or if the directory is the right. I think I first have to read more about maven... – Marv174 Jul 27 '16 at 12:35
  • It doesn't work with "LATEST" too, but know the exceptions says: Caused by: org.eclipse.aether.transfer.MetadataNotFoundException: Could not find metadata ouTest:projectTest/maven-metadata.xml in local (C:\Users\2202.DSACK\.m2\repository) – Marv174 Jul 27 '16 at 12:41
  • You are trying to bypass maven resolution right and want to load directly from a url. In that case this is a duplicate http://stackoverflow.com/questions/21186570/loading-drools-kie-workbench-artifacts-directly-from-the-repository#answer-21378844. Or ado you want to tie into the maven resolution? – raphaëλ Jul 27 '16 at 12:46
  • I've tried the as best accepted answer form [your link](http://stackoverflow.com/questions/21186570/loading-drools-kie-workbench-artifacts-directly-from-the-repository#answer-21378844) and the answer from craftsmannadeem but i always get the exception: org.eclipse.aether.transfer.MetadataNotFoundException: Could not find metadata ouTest:projectTest/maven-metadata.xml in local (C:\Users\2202.DSACK\.m2\repository) in \.m2\repository\ouTest\projectTest isn't a maven-metadata.xml but a maven-metadata-kie-wb.xml and the directory \.m2\repository\ouTest\projectTest\1.0 is empty – Marv174 Jul 27 '16 at 15:19
  • Why do you want to bypass maven and go directly to the kmodule? – raphaëλ Jul 27 '16 at 15:37
  • I don't really know how I can solve my problem. I've thought the answers are good examples. Is it better to tie into the maven resolution? And how do I do? I didn't found an detailed example in the drools doc. – Marv174 Jul 27 '16 at 15:57
  • These are two completely different deployment scenarios. You choose the above one for a reason? – raphaëλ Jul 27 '16 at 15:59
  • No, I just found an example and tried to adjust it for my project – Marv174 Jul 27 '16 at 16:05
  • You first need to think what you want? You want to provision the kiemodule to the application, you want this to happen at build time, or at runtime. At runtime do you need to reload based on a version/range and an interval or perhaps you want to access the rules remotely using a shared model? – raphaëλ Jul 27 '16 at 16:07
  • It would be great if I can load a data object, which was created in the kie workbench, into the application. Then I would like to fill the data object with values, submit it to the workbench and fire my rule wich I defined in the workbench, too – Marv174 Jul 28 '16 at 08:27
  • What do you mean with "load a data object, which was created in the kie workbench"? We can define facts in the workbench (i.e., classes) not objects (i.e, instance of a class). (Except for the tests) – raphaëλ Jul 28 '16 at 08:30
  • [Here](https://docs.jboss.org/drools/release/6.4.0.Final/drools-docs/html/ch18.html#wb.QuickStartDefineDataModel) it is called "Data Object" – Marv174 Jul 28 '16 at 08:42
  • Sorry though this was a different question (there is another question about pulling in database from database into the kie workbenc). In that case you will probably need to use a build time dependency or normally place those facttypes ("data objects") a different maven artefact, bind those at build time and pull the rules in at runtime. – raphaëλ Jul 28 '16 at 08:47
  • Do you know a good example to place a facttype. I don't even know how to start. – Marv174 Jul 28 '16 at 09:01
  • Most of the time people define the facttypes in a separate maven project typically outside of the workbench (in intellij/eclipse/jbds/etc) . Build the regular jar and upload it to the maven repository inside the workbench. Then within the project properties add the dependency. – raphaëλ Jul 28 '16 at 09:04
  • I've found the example [8.30](https://docs.jboss.org/drools/release/6.4.0.Final/drools-docs/html_single/#d0e8568) but I don't know where I have to save it, or which file format is used. How can I create a facttype? I only have the content at this point and there is no description what i should do with the content. I'm using eclipse if it matter – Marv174 Jul 28 '16 at 10:00
  • To me it sounds you are better off attending a drools training or follow some tutorial, – raphaëλ Jul 28 '16 at 10:14
  • Facttypes are just plain old Java Beans (with possibly some drools annotations). So just create a standard java maven project. Develop your facts as beans (with getter/setters, no behavioural methods), build the jar file and upload to the kie-wb. – raphaëλ Jul 28 '16 at 10:40
  • Do you know a good step by step tutorial? I've implemented a fact and build a jar and when i upload it to the kie-wb it says that the JAR does not contain a valid POM. Thats how my pom.xml looks like: 4.0.0 de.organisation drools-facttypes 0.0.1-SNAPSHOT – Marv174 Jul 28 '16 at 11:46
  • But I can manually put the GAV info but how do I know that I've done it right. – Marv174 Jul 28 '16 at 11:50

1 Answers1

1

I suppose u are trying to download the jar from Kie workbench,trying to build the jar in maven and use it inside your project.In that case ,first run this command as per the below link, http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html And then add your jar dependency in yor project pom file. You can use the below code to execute the application.U will need hell lot of jars in the course of execution.Kie-ci,kie-internal being the main ones.

            KieServices kieServices = KieServices.Factory.get(); 

            ReleaseId releaseId = kieServices.newReleaseId("org.test", 
                    "kie-project-simple", "1.0"); 

            KieContainer kContainer = kieServices.newKieContainer(releaseId); 

            kScanner = kieServices.newKieScanner(kContainer); 

            System.out.println("This is a Kie-Ci example. The drl rule is packaged " + 
                    "as a kmodule in a jar and deployed in your maven repo"); 

            // Scan to discover new resources of an existing artifact 
            kScanner.scanNow(); 

            for (int i = 0; i < 100; i++) { 
                // Create a stateless session 
                kSession = kContainer.newKieSession(); 
                kSession.insert("Hello"); 
                kSession.fireAllRules(); 
                try { 
                    Thread.sleep(5000); 
                } catch (InterruptedException e) { 
                    System.out.println("Thread interrupted. Firing of rules will stop."); 
                } 
            } 
Sushma
  • 81
  • 1
  • 5